Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Getting Last Non-Blank Row Number With VBA

Hi Everyone

In Excel I can place the following in a cell to get the last non blank
row number in column A. This works great and it's super quick.

=ROW(OFFSET(A1,COUNTA(A:A)-1,0))

To do the same with VBA code seems very complex. Can you please show
me some VBA code that will give me the last non-blank row number for a
given column?

Andy

  #2   Report Post  
Posted to microsoft.public.excel.programming
Ken Ken is offline
external usenet poster
 
Posts: 207
Default Getting Last Non-Blank Row Number With VBA

Andy

What your formula actually does is count how many non blanks there are
in column A, and give the row number of the cell that is offset one
less than that number from cell A1; which, if there are no blanks
cells in column A turns out to be the last non blank row number. If
there are any blanks, it won't give the number you want. To replicate
the functionality you described in VBA is pretty easy. All you have
to do is go to the bottom of the spreadsheet, end up to the last non
blank row with something in it. You don't say what you want to do
with the number, but

Sub Macro2()
MsgBox Cells(Rows.Count, 1).End(xlUp).Row
End Sub

will tell you what the number is.

I hope this helps.

Ken




On Apr 6, 3:52*pm, Andy wrote:
Hi Everyone

In Excel I can place the following in a cell to get the last non blank
row number in column A. *This works great and it's super quick.

=ROW(OFFSET(A1,COUNTA(A:A)-1,0))

To do the same with VBA code seems very complex. *Can you please show
me some VBA code that will give me the last non-blank row number for a
given column?

Andy


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Getting Last Non-Blank Row Number With VBA

Excellent!! Thanks Ken.
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
row number of last non-blank cell Bill Brehm Excel Worksheet Functions 12 January 16th 10 04:31 PM
Maximum Number of Blank Cells between Non Blank Cells in a Range Mal Excel Worksheet Functions 5 November 3rd 07 08:21 AM
How to find the first non-blank number in a row? RLind Excel Worksheet Functions 7 June 27th 07 04:58 AM
BLANK SPACE TO A NUMBER kevin Excel Worksheet Functions 3 December 30th 05 06:10 PM
First non blank number in a row Rajiv@Ivey Excel Discussion (Misc queries) 4 May 17th 05 12:19 AM


All times are GMT +1. The time now is 08:08 AM.

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

About Us

"It's about Microsoft Excel"