integrate tab color change into new sheet/renaming

minimalVBA

New Member
Joined
Dec 14, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello All,

I'm trying to kill 'two birds with one stone' with my macro. I'm trying to create a dynamic way to make new worksheets with renaming and tab color change. I'm able to create new worksheets with renaming. However, I'm at a lost on how to integrate tab color change. Basic set up is this, Column A has data validation list of 3 places: Home(green), East(yellow) and West(pink). Column B has a list of container information: Container1, Container2 and so forth. Caveat, container names are dynamic and constantly changing day by day. Below is the macro used to create worksheets and renaming it. Looking for help on how to integrate color tab changing into this (if possible)

1639488354595.png


Code used to create sheets/rename:

VBA Code:
Sub newsheetrename()

    Dim rng As Range
    Dim cell As Range
    On Error GoTo Errorhandling

    Set rng = Application.InputBox(Prompt:="Select cell range:", _
        Title:="Create sheets", _
        Default:=Selection.Address, Type:=8)
 
    For Each cell In rng
 
    Sheets.Add(After:=Sheets("Summary")).Name = cell

    Next cell

Errorhandling:

End Sub
 
Last edited by a moderator:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi & welcome to MrExcel.
Are you selecting col B & using that as the sheet name?
 
Upvote 0
Ok, how about
VBA Code:
Sub newsheetrename()
   Dim Rng As Range, Cell As Range
   On Error GoTo Errorhandling
   
   Set Rng = Application.InputBox(Prompt:="Select cell range:", _
   Title:="Create sheets", _
   Default:=Selection.Address, Type:=8)
   
   For Each Cell In Rng
      If Not Evaluate("isref('" & Cell.Value & "'!A1)") Then
         Sheets.Add(After:=Sheets("Summary")).Name = Cell.Value
         ActiveSheet.Tab.Color = Cell.Offset(, -1).Interior.Color
      End If
   Next Cell
   
Errorhandling:

End Sub
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,665
Members
449,045
Latest member
Marcus05

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