+ Reply to Thread
Results 1 to 8 of 8

Macro to only run on sheet1 IF the active sheet, what code?

Hybrid View

thecdnmole Macro to only run on sheet1... 01-05-2019, 04:00 PM
mjr veverka Re: Macro to only run on... 01-05-2019, 04:10 PM
Fluff13 Re: Macro to only run on... 01-05-2019, 04:12 PM
thecdnmole Re: Macro to only run on... 01-05-2019, 04:13 PM
thecdnmole Re: Macro to only run on... 01-05-2019, 04:29 PM
Fluff13 Re: Macro to only run on... 01-05-2019, 04:38 PM
thecdnmole Re: Macro to only run on... 01-05-2019, 04:59 PM
Fluff13 Re: Macro to only run on... 01-05-2019, 05:34 PM
  1. #1
    Forum Contributor
    Join Date
    08-22-2009
    Location
    Manitoba
    MS-Off Ver
    Office 2010
    Posts
    524

    Macro to only run on sheet1 IF the active sheet, what code?

    Hi, I am having a brain fart here. I have code that I only want to run when sheet1 is the active sheet. It can be called with keyboard shortcut keys from any sheet which is why I only want it to run when sheet1 is the activesheet. Probably simple, but I just can't get anything to work. Thanks!

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,277

    Re: Macro to only run on sheet1 IF the active sheet, what code?

    Try
    (assign a shortcut to a new macro: 'macro_1')
    Sub macro_1()
        If ActiveSheet.Name = "Sheet1" Then Call my_macro 'here the name of your macro (i.e. instead of my_macro)
    End Sub
    Last edited by mjr veverka; 01-05-2019 at 04:12 PM.

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Macro to only run on sheet1 IF the active sheet, what code?

    Another option.
    Simply add this to the start of you macro
    If ActiveSheet.Name <> "Sheet1" Then Exit Sub

  4. #4
    Forum Contributor
    Join Date
    08-22-2009
    Location
    Manitoba
    MS-Off Ver
    Office 2010
    Posts
    524

    Re: Macro to only run on sheet1 IF the active sheet, what code?

    Thanks PV! I have been searching all morning and a minute after I posted this, I searched again and found much the same as what you suggested. https://www.mrexcel.com/forum/excel-...sheet-vba.html . Thanks.

  5. #5
    Forum Contributor
    Join Date
    08-22-2009
    Location
    Manitoba
    MS-Off Ver
    Office 2010
    Posts
    524

    Re: Macro to only run on sheet1 IF the active sheet, what code?

    Hmmm, want a code to run if either of two sheets are Active, but this does not work?
    If ActiveSheet.CodeName <> "Sheet24" Or ActiveSheet.CodeName <> "Sheet26" Then Exit Sub

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Macro to only run on sheet1 IF the active sheet, what code?

    Try
    If ActiveSheet.CodeName <> "Sheet17" And ActiveSheet.CodeName <> "Sheet8" Then Exit Sub
    and thanks for the Rep

  7. #7
    Forum Contributor
    Join Date
    08-22-2009
    Location
    Manitoba
    MS-Off Ver
    Office 2010
    Posts
    524

    Re: Macro to only run on sheet1 IF the active sheet, what code?

    Thanks Fluff13, that works!

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Macro to only run on sheet1 IF the active sheet, what code?

    You're welcome & thanks for the feedback

+ 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. [SOLVED] VBA gives results in active sheet (sheet1) instead of sheet2
    By Akbarov in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-13-2018, 04:59 AM
  2. [SOLVED] How to keep sheet1(output) active while searching sheet2(data) stop sheet switching
    By khhoa in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-14-2014, 08:18 PM
  3. Macro to go back to the last active sheet and hide the active sheet
    By yatahaze in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-20-2014, 08:18 AM
  4. Need macro code for filling values in Sheet 2 by taking input parameters from Sheet1
    By ashaanna88 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-01-2012, 09:32 AM
  5. Replies: 1
    Last Post: 09-30-2012, 07:35 PM
  6. [SOLVED] How to get (range)macro to always run code on a specific sheet regardless of active sheet?
    By JTwrk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-18-2012, 04:33 PM
  7. Send the mail from an active sheet - VB code for macro
    By Geetha Ramakrishnan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-11-2011, 07:23 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