Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Finding the last nonblank cell in a column in VBA or VSTO

Folks,

In VBA I have frequently used the formula:

last_row = ActiveWorkbook.Sheets("Sheet1").Range("A65534").En d(xlUp).Row

to find the last cell with data in it in column A of Sheet1.

In Visual Studio Tools for Office (C#) the equivalent expression I have just
discovered is:

Sheet1.get_Range("A65534", Type.Missing).get_End(Excel.XlDirection.xlUp).Row

--
Bob Sullentrup
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 230
Default Finding the last nonblank cell in a column in VBA or VSTO

Your method would not work if the last cell used was on row 65534, 65535, or
65536. Even if you corrected your typo (should have said 65536), if the data
extended to row 65536, you'd end either on Row 1 or on the last occurrence
of a break in the data, using End(xlUP). And what if there is no data in Col
A ... or what if the data in colums other than A extended below rows which
Col A's data held? There are a lot of other ways to get last row. The
quickest I know is:
Activesheet.UsedRange.SpecialCells(xlcelltypelastc ell).Row



"Bob Sullentrup" wrote in message
...
Folks,

In VBA I have frequently used the formula:

last_row = ActiveWorkbook.Sheets("Sheet1").Range("A65534").En d(xlUp).Row

to find the last cell with data in it in column A of Sheet1.

In Visual Studio Tools for Office (C#) the equivalent expression I have
just
discovered is:

Sheet1.get_Range("A65534",
Type.Missing).get_End(Excel.XlDirection.xlUp).Row

--
Bob Sullentrup



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count nonblank cells based on another column SandyB Excel Worksheet Functions 1 January 12th 09 10:33 PM
CELL EQUALS LAST NONBLANK CELL IN A COLUMN Vicky Excel Worksheet Functions 5 February 29th 08 06:18 PM
Require a cell to be nonblank if another cell is nonblank Herb Wexler Excel Discussion (Misc queries) 1 February 1st 06 08:05 PM
Find last nonblank in a column George W. Barrowcliff Excel Worksheet Functions 12 July 26th 05 05:40 PM
Find last nonblank cell in column Pink Panther Excel Programming 4 July 21st 05 12:16 AM


All times are GMT +1. The time now is 11:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"