VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > Excel Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Reply
 
Thread Tools Display Modes
Old 04-30-2012, 03:54 AM   #1
asdzxc

 
Joined: Apr 2012
Posts: 68
Kb Entries: 0
Articles: 0
select last 20 cells

vba code for selecting last 20 cells, if cells less than 20, say10
select A2:B11.
plse see attached file.
Attached Files To view attachments your post count must be 0 or greater. Your post count is 0 momentarily.

Local Time: 11:20 AM
Local Date: 05-19-2013
Location:

 
Reply With Quote Top
Old 04-30-2012, 04:46 AM   #2
xld
 
xld's Avatar
Distinguished Lord of VBAX

 
Joined: Apr 2005
Posts: 23,118
Kb Entries: 3
Articles: 2
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 tags courtesy of www.thecodenet.com


____________________________________________
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

Local Time: 04:20 AM
Local Date: 05-19-2013
Location:

 
Reply With Quote Top
Old 04-30-2012, 05:10 AM   #3
asdzxc

 
Joined: Apr 2012
Posts: 68
Kb Entries: 0
Articles: 0
select last 20 cells

Quote:
 
Originally Posted by: xld
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 tags courtesy of www.thecodenet.com


thank you for quick reply.
your vba select only A11:A30 but I want A11:B30

Local Time: 11:20 AM
Local Date: 05-19-2013
Location:

 
Reply With Quote Top
Old 04-30-2012, 06:52 AM   #4
xld
 
xld's Avatar
Distinguished Lord of VBAX

 
Joined: Apr 2005
Posts: 23,118
Kb Entries: 3
Articles: 2
VBA:
Cells(lastrow - selectnum + 1, "A").Resize(selectnum, 2).Select
VBA tags courtesy of www.thecodenet.com


____________________________________________
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

Local Time: 04:20 AM
Local Date: 05-19-2013
Location:

 
Reply With Quote Top
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 08:20 PM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2012 VBA Express