Run code only if activesheet.name is Sheet 1 or Sheet 2

Ironman

Board Regular
Joined
Jan 31, 2004
Messages
186
Hi

I have the following code:
Code:
If ActiveSheet.Name <> "Training Log" Then Exit Sub

I'm trying to amend this so that the code will also run if the active sheet is called "Analysis" (without the commas)

I've tried
Code:
If ActiveSheet.Name <> "Training Log" or "Analysis" Then Exit Sub
but this errors.

Can you help me please?

Thank you
 
Last edited:

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,110
Office Version
  1. 365
Platform
  1. Windows
Try:

Code:
If ActiveSheet.Name <> "Training Log" And ActiveSheet.Name <> "Analysis" Then Exit Sub

You need both conditions to be true so you need and rather than or.
 

tyija1995

Well-known Member
Joined
Feb 26, 2019
Messages
766
Office Version
  1. 365
Platform
  1. Windows
Hi Ironman,

Try this:
Code:
If ActiveSheet.Name <> "Training Log" And ActiveSheet.Name <> "Analysis" Then Exit Sub
MsgBox "Hi"

You should see "Hi" if you are in training log or analysis worksheet, otherwise nothing.
 

tyija1995

Well-known Member
Joined
Feb 26, 2019
Messages
766
Office Version
  1. 365
Platform
  1. Windows
Glad we could help!
Apologies for the duplicated code, I was mid-typing up the post when Steve replied so never saw his reply before I sent off mine :D
 

Watch MrExcel Video

Forum statistics

Threads
1,109,383
Messages
5,528,385
Members
409,817
Latest member
JiNXX9500

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top