![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Apr 2002
Posts: 169
|
I am trying to find the last row in a certain column. I know how to it for a sheet. See below ActiveSheet.UsedRange ActiveCell.SpecialCell(xlLastCell).Select glngLastRow = ActiveCell.Row gintLastCol = ActiveCell.Column I thought to find the last row for a column I could go. Columns(intCol).UsedRange ActiveCell.SpecialCell(xlLastCell).Select glngLastRow = ActiveCell.Row gintLastCol = ActiveCell.Column But this does not work because I get an error at "Columns(intCol).UsedRange" when I run the code. Any ideas. I have one, finding the blank row of the column I want but is there another way. |
|
|
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
Sub LastRowInColumn() '// I F M Dim rLastRow As Range Dim intCol As Integer '// Where intCol is the column to search intCol = 2 Set rLastRow = Columns(intCol).Find(What:="*", SearchDirection:=xlPrevious, _ SearchOrder:=xlByRows) If rLastRow Is Nothing Then Set rLastRow = Columns(intCol).End(xlDown) MsgBox rLastRow.Address Else MsgBox rLastRow.Address End If End Sub _________________ Kind Regards, Ivan F Moala From the City of Sails ![]() [ This Message was edited by: Ivan F Moala on 2002-05-23 09:32 ] |
|
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
Hello,
You could use this function:- Code:
Function LastRow(ColumnNumber As Long)
Dim rngeCol As Range
On Error Resume Next
If ColumnNumber < 1 Or ColumnNumber > 256 Then
LastRow = "Invalid column number"
Exit Function
End If
Set rngeCol = ActiveSheet.Columns(ColumnNumber)
LastRow = rngeCol.Find(What:="*", SearchDirection:=xlPrevious).Row
End Function
Code:
Sub TestIt() MsgBox "The last used cell in column A is in row " & LastRow(1) End Sub Dan |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|