+ Reply to Thread
Results 1 to 5 of 5

VBA to define dynamic macro name using cell value?

  1. #1
    Forum Contributor
    Join Date
    07-22-2009
    Location
    Minneapolis, MN
    MS-Off Ver
    2016
    Posts
    220

    VBA to define dynamic macro name using cell value?

    Context:

    I have a workbook with 15 sheets.
    I have a macro for each sheet called "RESET_Sheet1", "RESET_Sheet2", "RESET_Sheet3", etc (each RESET_ macro is unique to the respective sheet so can't just make one generic RESET_ macro for all sheets)
    On a hidden sheet I have a named range that lists each sheet name.
    I'm trying to finish a simple macro that loops through each sheet in that list and 1) selects the sheet, 2) calls the RESET_SheetX macro.

    The macro runs fine except for the part about calculating the macro name for the specific sheet and call it. I tried something like this, but it doesn't work.

    Please Login or Register  to view this content.
    I've been googling and trying possible solutions, but keep coming up empty so it's time to break out the big guns and ask yall.

    Any ideas how to make that work?

  2. #2
    Forum Contributor
    Join Date
    07-22-2009
    Location
    Minneapolis, MN
    MS-Off Ver
    2016
    Posts
    220

    Re: VBA to define dynamic macro name using cell value?

    Figures; I figured it out minutes after posting the question...

    For posterity, here's what I came up with.

    Please Login or Register  to view this content.
    If you have a better way to do it I'd love to hear/see it.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: VBA to define dynamic macro name using cell value?

    That could probably be just:
    Please Login or Register  to view this content.
    If you process every sheet, maybe something like:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Contributor
    Join Date
    07-22-2009
    Location
    Minneapolis, MN
    MS-Off Ver
    2016
    Posts
    220
    Quote Originally Posted by TMS View Post
    That could probably be just:
    Please Login or Register  to view this content.
    If you process every sheet, maybe something like:

    Please Login or Register  to view this content.
    I'll test that out, thanks!

    That second bit of code is great too, but unfortunately won't work for this application since I'm not doing every sheet in the workbook (there are more sheets than what's in that list). I'll keep that handy though, I'm sure I'll use it somewhwre eventually.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: VBA to define dynamic macro name using cell value?

    You're welcome.

    Post a sample workbook. You are using ActiveCell which implies your code is selecting cells in the loop. That can, and should, be avoided. So, there are better ways. We just need more detail.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need to define a search or define instruction to extract parts of data from cell
    By Dawn Clark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-12-2021, 02:45 AM
  2. Define Dynamic Range
    By ionelz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-22-2020, 11:17 AM
  3. [SOLVED] dynamic range/define name
    By Jhon Mustofa in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 08-28-2013, 10:39 PM
  4. Define dynamic data range
    By SH14 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2011, 08:17 AM
  5. how to define dynamic range?
    By jay11 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-26-2011, 02:14 PM
  6. PRoblems Define Dynamic Range
    By ions in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-03-2007, 04:55 PM
  7. [SOLVED] Macro - define cell range for a sum function
    By Fad in forum Excel General
    Replies: 2
    Last Post: 06-06-2005, 08:05 AM

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