+ Reply to Thread
Results 1 to 3 of 3

Allowing for variable cell reference in macro

  1. #1
    Registered User
    Join Date
    06-29-2005
    Posts
    77

    Allowing for variable cell reference in macro

    Hi

    What I'd like to figure out is how to get a macro to read from data placed in a cell, and then apply that data to the macro.

    like:

    Sub Macro1()

    Range(">>TBD<<").Select
    Selection.sort Key1:=Range("I1"), Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False

    End Sub


    where the range is read from some other cell on the spreadsheet. so the macro reads what is in the cell telling it what range to sort, and then enters that in the Range("").Select area of the macro.

    Otherwise I have to create a separate macro for every area that might possibly apply. I'd like to create an intelligent macro that I tell what range to sort, or delete, or copy, or paste, etc, whatever I want to happen with the range of cells I select.

    Any ideas?

    Thx

  2. #2
    Gary''s Student
    Guest

    RE: Allowing for variable cell reference in macro

    Let's say that A1 contains the text Z100, the following:


    Sub Macro1()
    Dim s As String
    s = Cells(1, 1)
    Range(s).Select
    End Sub

    will get the contents of A1 (as a string) convert it into a range and select
    that range. You could apply it to ranges of more than one cell.
    --
    Gary's Student


    "tx12345" wrote:

    >
    > Hi
    >
    > What I'd like to figure out is how to get a macro to read from data
    > placed in a cell, and then apply that data to the macro.
    >
    > like:
    >
    > Sub Macro1()
    >
    > Range(">>TBD<<").Select
    > Selection.sort Key1:=Range("I1"), Order1:=xlAscending,
    > Header:=xlGuess, _
    > OrderCustom:=1, MatchCase:=False
    >
    > End Sub
    >
    >
    > where the range is read from some other cell on the spreadsheet. so the
    > macro reads what is in the cell telling it what range to sort, and then
    > enters that in the Range("").Select area of the macro.
    >
    > Otherwise I have to create a separate macro for every area that might
    > possibly apply. I'd like to create an intelligent macro that I tell
    > what range to sort, or delete, or copy, or paste, etc, whatever I want
    > to happen with the range of cells I select.
    >
    > Any ideas?
    >
    > Thx
    >
    >
    > --
    > tx12345
    > ------------------------------------------------------------------------
    > tx12345's Profile: http://www.excelforum.com/member.php...o&userid=24776
    > View this thread: http://www.excelforum.com/showthread...hreadid=495872
    >
    >


  3. #3
    Registered User
    Join Date
    06-29-2005
    Posts
    77
    nothing like a simple solution. many thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1