11.08.2013 Views

Excel's Formula - sisman

Excel's Formula - sisman

Excel's Formula - sisman

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 24: VBA Programming Concepts 667<br />

Figure 24-2: Use the Intersect function to work with the intersection of two ranges.<br />

The CELLSINCOMMON function uses the Intersect function to create a range object named<br />

CommonCells. Note the use of On Error Resume Next. This statement is necessary<br />

because the Intersect function returns an error if the ranges have no cells in common. If the<br />

error occurs, it is ignored. The final statement checks the Number property of the Err object.<br />

If it is 0, no error occurs, and the function returns the value of the CountLarge property for the<br />

CommonCells object. If an error does occur, Err.Number has a value other than 0, and the<br />

function returns 0.<br />

The Union function<br />

The Union function combines two or more ranges into a single range. The following statement<br />

uses the Union function to create a range object that consists of the first and third columns of a<br />

worksheet:<br />

Set TwoCols = Union(Range(“A:A”), Range(“C:C”))<br />

The Union function takes between 2 and 30 arguments.<br />

The UsedRange property<br />

The UsedRange property returns a Range object that represents the used range of the worksheet.<br />

Press Ctrl+End to activate the lower-right cell of the used range. The UsedRange property<br />

can be very useful in making your functions more efficient.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!