How do I determine the last cell in a Column

A

Ayo

I know how to get the last cell in a column:

range("A65536").End(xlUp).address for the row number
range("A65536").End(xlUp).row for the row number

but I am not sure how to translate this to doing the same for the row.
Any help with be appreciated. Thanks.
 
S

Sheeloo

Try...
Range("IV1").End(xlToLeft).Column

I prefer to use...

With ActiveSheet
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
lastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With
 
A

Ayo

Thanks Sheeloo. One more question, how do I use it in a for statement that
is looping through cells D14: T14 i.e.,

For Each c In Wsht.Range((4, 14), (4, lastColumn)).Cells
If c.Value = Range("B4") Then
getMSaddress = c.Address(ColumnAbsolute:=False)
Exit Function
End If
Next c
 
D

Dave Peterson

dim c as range
Dim myRng as range
with wsht
set myrng = .range(.cells(4,14), .cells(4,lastcol))
end with

for each c in myrng.cells
.....
 
A

Ayo

Thanks Dave.

Dave Peterson said:
dim c as range
Dim myRng as range
with wsht
set myrng = .range(.cells(4,14), .cells(4,lastcol))
end with

for each c in myrng.cells
.....
 
S

Sheeloo

Try
Wsht.Range(Cells(14, 4), Cells(14, lastColumn)).Select
For Each c In Selection
If c.Value = Range("B4") Then
getMSaddress = c.Address
Exit For
End If
Next c
 
D

Dave Peterson

This could cause trouble.

If you're going to qualify .range, it's a good idea to qualify cells:

Wsht.Range(wsht.Cells(14, 4), wsht.Cells(14, lastColumn)).Select

And if wsht isn't the activesheet, then the .Select will fail. I wouldn't
select the range to work on it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top