Change tab colour if text in column N

raphagcwill

New Member
Joined
Jan 12, 2016
Messages
41
Hi there,

wondering if you could help me to make the below.

I have a workbook with more then 20 sheets. My goal is to make each tabs change colour if a specific text is found on column N

I have managed to write the below code, but it takes 10 seconds for it to complete the task. It is worth saying that I am not very familiar with VBA and that the below was the result of me combining solutions i found on the internet loops - Excel VBA; If a value in column M equals x then column A should Equal Column E - Stack Overflow

Can somebody help me to make it faster? Should I insert a lastrow on my code?

Thanks in advance


Sub CHANGE_TAB_COLOUR()




Dim SOURCEWS As Worksheet
Set SOURCEWS = ActiveSheet


Dim lngLoop As Long
Dim LastRow As Long


lngLoop = 1


For lngLoop = 1 To Rows.Count


If Cells(lngLoop, 14).Value = "SETTLE" Then
With SOURCEWS.Tab
.Color = 5296274
.TintAndShade = 0
End With
ElseIf Cells(lngLoop, 14).Value = "PPO" Then
With SOURCEWS.Tab
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
End With
ElseIf Cells(lngLoop, 14) = "PO" Then
With SOURCEWS.Tab
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
End With


End If
Next




End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Untested:

Code:
Sub CHANGE_TAB_COLOUR()
  Dim wks           As Worksheet
  Dim vs            As Variant
  Dim rFind         As Range

  Set wks = ActiveSheet

  With wks
    For Each vs In Array("SETTLE", "PPO", "PO")
      Set rFind = .Range("N:N").Find(What:=vs, LookAt:=xlWhole, MatchCase:=True)
      If Not rFind Is Nothing Then
        If vs = "SETTLE" Then
          .Tab.Color = 5296274
          .Tab.TintAndShade = 0
        Else
          .Tab.ThemeColor = xlThemeColorDark1
          .Tab.TintAndShade = -0.15
        End If
        Exit Sub
      End If
    Next vs
  End With
End Sub
 
Upvote 0
Solution
Thanks for you prompt reply, shg.

It is way faster and no error has been found. Bt there is one problem.

the tab colour changes always to green, even when "po" and "ppo" are found.

If column contains only "Settle" then the tab should turn to gree, otherwise remain unchangedm whh is the same as ( .Tab.ThemeColor = xlThemeColorDark1Tab.TintAndShade = -0.15)

Thans in advance
 
Upvote 0
Hello again,

Could you please help to make this makro loop thru all wotksheets?
As of now i have to manually run it on all the 20 + sheets my wotkbook has.
Tried copying in to the makro that creates the sheets, but nothing happens.

Once again, thanks for the help

Sub CHANGE_TAB_COLOUR()
Dim wks As Worksheet
Dim vs As Variant
Dim rFind As Range

Set wks = ActiveSheet

With wks
For Each vs In Array("PO", "PPO", "SETTLE")
Set rFind = .Range("N:N").Find(What:=vs, LookAt:=xlWhole, MatchCase:=True)
If Not rFind Is Nothing Then
If vs = "SETTLE" Then
.Tab.Color = 5296274
.Tab.TintAndShade = 0
Else
.Tab.ThemeColor = xlThemeColorDark1
.Tab.TintAndShade = -0.15
End If
Exit Sub
End If
Next vs
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,019
Messages
6,128,311
Members
449,439
Latest member
laurenwydo

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