Log in

View Full Version : Macro - select range based on cell data


murphyt10
Aug 12, 2009, 10:45 AM
I need a macro that will select a range based on a number in a cell. If the number in the cell (in this case the cell is K1) is 200 then I want to select Range A2:D201, if it was 100 then select Range A2:D101.

Thanks for the help!

twinkiedooter
Aug 12, 2009, 11:35 AM
Sounds right to me. Try it and see if it works.

murphyt10
Aug 12, 2009, 11:42 AM
The answer that was posted seems to have gotten deleted, can you repost please? Thanks!

JBeaucaire
Aug 12, 2009, 01:47 PM
Following your question, this does what you ask:

Sub SelectRange()
Dim LR As Long
LR = Range("K1").Value + 1

Range("A2:A" & LR).Select

End Sub

It's possible to have the macro figure out how many cells in column A have data in them, if you wish to automate that, too, so you don't have to put a value in K1:


Sub SelectRange()
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row

Range("A2:A" & LR).Select

End Sub

HeidiG
Aug 3, 2012, 01:53 AM
That bit of code helped me very much. Thanks :-)