+ Reply to Thread
Results 1 to 3 of 3

How to use a cell value in a macro

  1. #1
    Registered User
    Join Date
    07-29-2012
    Location
    Guernsey, Channel Islands, UK
    MS-Off Ver
    Excel 2010
    Posts
    13

    How to use a cell value in a macro

    Hi, I am trying to use a cell value in a macro to change what it does.

    I want a macro to run Autofilter, Sort and Hide/Unhide columns, and selecting sheets based on certain cells.


    For example, on my spreadsheet of race times for various events I may want columns X:Z hidden if the user selected to not see that event.

    I was going to use a DDL for the user to select which event they want to see, then in a seperate cell use a lookup to return the cells to be hidden. eg. User selects "round 1" and cell "Home!N3" will return X:Z. I want to use the value of the cell "X:Z" in the macro.

    As I said above, I have a few applications for this, so is there a simple way of just adding the cell value as and where I need it? I do not know much VBA, just enough to basically read it and edit it as I need to. When I go to my recorded macro for any of the uses I mentioned above, I want to be able to change, for example, "X:Z" to a code amounting to the value of the cell with the information in it "Home!N3".


    I have tried just changing to a different sheet with no luck and have tried many combinations of something like Sheets("Champs!C5".Value).Select


    Any help, or advice of what to search on and learn would be appreciated.

    Thanks, KAL46

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: How to use a cell value in a macro

    Hi, kal46,

    assuming that cell C10 delivers the string M:Q and that you want to hide the columns M to Q on the active sheet:
    Please Login or Register  to view this content.
    Regarding the changing of a worksheet (I really donīt see a necessity to do so), the name of the worksheet is in C5 on Sheet Champs:
    Please Login or Register  to view this content.
    Cia,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    07-29-2012
    Location
    Guernsey, Channel Islands, UK
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: How to use a cell value in a macro

    Hi Holger,

    That's great. Both work, also used the same basis for autofilter and that worked too. Just got to try using it on my sort function and that will be it all done, i'll try it tomorrow.

    Thanks again. KAL46

+ 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