Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Spreadsheets (https://www.askmehelpdesk.com/forumdisplay.php?f=395)
-   -   Macro - select range based on cell data (https://www.askmehelpdesk.com/showthread.php?t=386168)

  • Aug 12, 2009, 10:45 AM
    murphyt10
    Macro - select range based on cell data
    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!
  • Aug 12, 2009, 11:35 AM
    twinkiedooter

    Sounds right to me. Try it and see if it works.
  • Aug 12, 2009, 11:42 AM
    murphyt10

    The answer that was posted seems to have gotten deleted, can you repost please? Thanks!
  • Aug 12, 2009, 01:47 PM
    JBeaucaire

    Following your question, this does what you ask:
    Code:

    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:

    Code:

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

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

    End Sub

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

  • All times are GMT -7. The time now is 03:31 AM.