View Full Version : select last 20 cells
asdzxc
04-30-2012, 03:54 AM
vba code for selecting last 20 cells, if cells less than 20, say10
select A2:B11.
plse see attached file.
Bob Phillips
04-30-2012, 04:46 AM
One very direct way
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
asdzxc
04-30-2012, 05:10 AM
One very direct way
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
thank you for quick reply.
your vba select only A11:A30 but I want A11:B30
Bob Phillips
04-30-2012, 06:52 AM
Cells(lastrow - selectnum + 1, "A").Resize(selectnum, 2).Select
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.