vba code for selecting last 20 cells, if cells less than 20, say10
select A2:B11.
plse see attached file.
vba code for selecting last 20 cells, if cells less than 20, say10
select A2:B11.
plse see attached file.
One very direct way
[vba]Dim lastrow As Long
Dim selectnum As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Select Case True
Case lastrow > 20: selectnum = 20
Case lastrow > 10: selectnum = 10
Case lastrow > 5: selectnum = lastrow
End Select
Cells(lastrow - selectnum + 1, "A").Resize(selectnum).Select
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
thank you for quick reply.Originally Posted by xld
your vba select only A11:A30 but I want A11:B30
[vba]
Cells(lastrow - selectnum + 1, "A").Resize(selectnum, 2).Select [/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber