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 25: VBA Custom Function Examples 697<br />

These functions are available on the companion CD-ROM, in a file named extended<br />

date functions.xlsm. The CD also contains a Word file (extended date functions<br />

help.docx) that describes these functions.<br />

The extended date functions don’t make any adjustments for changes made to the<br />

calendar in 1582. Consequently, working with dates prior to October 15, 1582, may not<br />

yield correct results.<br />

Returning the Last Nonempty Cell<br />

in a Column or Row<br />

This section presents two useful functions: LASTINCOLUMN, which returns the contents of the<br />

last nonempty cell in a column, and LASTINROW, which returns the contents of the last nonempty<br />

cell in a row. Chapter 15 presents array formulas for this task, but you may prefer to use a<br />

custom function.<br />

The companion CD-ROM contains last nonempty cell.xlsm, a workbook that demonstrates<br />

the functions presented in this section.<br />

Each of these functions accepts a range as its single argument. The range argument can be a column<br />

reference (for LASTINCOLUMN) or a row reference (for LASTINROW). If the supplied argument<br />

is not a complete column or row reference (such as 3:3 or D:D), the function uses the<br />

column or row of the upper-left cell in the range. For example, the following formula returns the<br />

contents of the last nonempty cell in column B:<br />

=LASTINCOLUMN(B5)<br />

The following formula returns the contents of the last nonempty cell in row 7:<br />

=LASTINROW(C7:D9)<br />

The LASTINCOLUMN function<br />

The following is the LASTINCOLUMN function:

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

Saved successfully!

Ooh no, something went wrong!