create specific tabs if they're not already in the file

SandsB

Well-known Member
Joined
Feb 13, 2007
Messages
731
Office Version
  1. 365
Platform
  1. Windows
My file could have about 30 tabs in it, one for each volunteer. If a volunteer didn't work on a particular day there's no tab for him. That's always been OK but now I need to add a tab that looks at a list of volunteers and if a person doesn't already have a tab in the file I need a blank tab created, named for the volunteer, with just the word "OFF" in A1.
The file already has a list of all the volunteers in column A of a tab named Vol. so the macro could look at the list to see what tabs already exist. The number of volunteers changes all the time so the number of people in the list changes, too.

So - if today 28 volunteers worked the file already has 29 tabs in it. 28 named for each of the volunteers and one named Vol with the names of all volunteers. Bob Jones and John Smith took the day off. I need a macro that will create a tab named Bob Jones and and other tab named John Smith and put the word OFF in A1 of each of those tabs.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
How about
Code:
Sub SandsB()
   Dim Cl As Range
   With Sheets("Vol")
      For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
         If Not Evaluate("Isref('" & Cl.Value & "'!a1)") Then
            Sheets.Add(, Sheets.Count).Name = Cl.Value
            Range("A1").Value = "OFF"
         End If
      Next Cl
   End With
End Sub
 
Upvote 0
Sheets.Add(, Sheets.Count).Name = Cl.Value

This line gives me an error I'm not sure about:

Run-time error '1004'
Method 'Add' of object "Sheets" failed
 
Upvote 0
Oops, that line should be
Code:
            Sheets.Add(, Sheets(Sheets.Count)).Name = Cl.Value
 
Last edited:
Upvote 0
Stupid user question. This will save me a lot of time.

How could this be made to work if the Vol tab was in a separate file named MyFile.xlsx?
 
Upvote 0
@mayday1
Like
Code:
   Dim Cl As Range
   
   ThisWorkbook.Activate
   With Workbooks("Book1.xlsm").Sheets("Vol")
      For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
         If Not Evaluate("isref('" & Cl.Value & "'!a1)") Then
            Sheets.Add(, Sheets(Sheets.Count)).Name = Cl.Value
            Range("A1").Value = "OFF"
         End If
      Next Cl
   End With
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top