Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Find last used row in a column (not in the whole worksheet)

Hi all,

I was wondering if you can help me with this:

I need to:
1) identify the last used row in a column (not in the whole worksheet)
2) identify whether a column is blank or not

The two are of course related - if I figure out for the 1st point,
then the other is straightforward.

Any suggestions?

Thanks in advance!

PS I use Excel 2007
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Find last used row in a column (not in the whole worksheet)

dim myCol as long
dim LastRow as long
mycol = 123 'an example

lastrow = -1 'never happen in excel!
with activesheet
if application.counta(.cells(1,mycol).entirecolumn) = 0 then
msgbox "the column is empty"
else
lastrow = .cells(.rows.count,mycol).end(xlup).row
msgbox lastrow
end if
end with


" wrote:

Hi all,

I was wondering if you can help me with this:

I need to:
1) identify the last used row in a column (not in the whole worksheet)
2) identify whether a column is blank or not

The two are of course related - if I figure out for the 1st point,
then the other is straightforward.

Any suggestions?

Thanks in advance!

PS I use Excel 2007


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Find last used row in a column (not in the whole worksheet)

Thanks! In the meanwhile, I came up with this:

Function FindLastRowInColumn(MyColumn As Integer, _
MyWorksheet As Worksheet)

'MyColumn: Column being searched
'MyWorksheet: Worksheet being searched

'Output: last used row; if 0 == blank column

Dim MyRange As Range

Set MyRange = MyWorksheet.Cells(1,
MyColumn).EntireColumn.Find("*", _
SearchDirection:=xlPrevious)

If MyRange Is Nothing Then
FindLastRowInColumn = 0
Else
FindLastRowInColumn = MyRange.Row
End If


End Function

Dave Peterson wrote:
dim myCol as long
dim LastRow as long
mycol = 123 'an example

lastrow = -1 'never happen in excel!
with activesheet
if application.counta(.cells(1,mycol).entirecolumn) = 0 then
msgbox "the column is empty"
else
lastrow = .cells(.rows.count,mycol).end(xlup).row
msgbox lastrow
end if
end with

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
How do I find duplicate entries in a column in an Excel worksheet? Chunka Excel Discussion (Misc queries) 19 April 23rd 10 07:43 PM
Can't find Column A in my worksheet Ayo Excel Discussion (Misc queries) 3 October 13th 09 10:34 PM
Open Workbook, Go To Worksheet ABC, Find XYZ In Column B Steve[_91_] Excel Programming 3 September 8th 07 02:47 PM
Vlookup worksheet, find value in any column PeterH Excel Worksheet Functions 5 May 17th 07 05:19 AM
FIND A TEXT IN A WORKSHEET NOT IN A COLUMN OR ROW BY FORMULA peyman Excel Discussion (Misc queries) 1 August 24th 06 03:57 PM


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

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"