tidy betty

fry

Active Member
Joined
Apr 25, 2007
Messages
411
Hi again all

Could someone please help me tidy up and condense the following code...

Code:
For r = 11 To 12
On Error Resume Next
w = WorksheetFunction.Search("boc", Cells(r, "B"))
x = WorksheetFunction.Search("a-plant", Cells(r, "B"))
y = WorksheetFunction.Search("a plant", Cells(r, "B"))
z = WorksheetFunction.Search("adlington", Cells(r, "B"))
If w > 0 Then
ActiveSheet.Tab.ColorIndex = 5
End If
If x > 0 Then
ActiveSheet.Tab.ColorIndex = 10
End If
If y > 0 Then
ActiveSheet.Tab.ColorIndex = 10
End If
If z > 0 Then
ActiveSheet.Tab.ColorIndex = 10
End If
Next

Many Thanks :)

P.S. Sorry for the DOUBLE post above but my puter crashed mid submit!!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi
try the following codes
Code:
Sub hhh()
For a = 1 To 4
b = Choose(a, "boc", "a-plant", "a plant", "adlington")
c = Choose(a, 5, 10, 10, 10)
If Cells(11, 2) = b Or Cells(12, 2) = b Then
ActiveSheet.tab.ColorIndex = c
End If
Next a
End Sub
Ravi
 
Upvote 0
Code:
Option Base 1
Public Sub trythis()
On Error Resume Next
Dim arr() As Variant
Dim i As Integer
arr = Array("boc", "a-plant", "a plant", "adlington")
For i = 1 To 4
        If Not IsError(Application.Search(arr(i), Cells(11, "B"))) Or Not IsError(Application.Search(arr(i), Cells(12, "B"))) Then
            Select Case i
                Case 1
                ActiveSheet.Tab.ColorIndex = 5
                Case Is > 1
                ActiveSheet.Tab.ColorIndex = 10
            End Select
        End If
Next
End Sub
 
Upvote 0
This is a shot in the dark since I've no idea if there could be any other values in B11/12 that you need to deal with.
Code:
    If InStr(Range("B11"), "boc") <> 0 Or InStr(Range("B12"), "boc") <> 0 Then
        ActiveSheet.Tab.ColorIndex = 5
    End If
    
    If Left(Range("B11"), 1) = "a" Or Left(Range("B12"), 1) = "a" Then
        ActiveSheet.Tab.ColorIndex = 10
    End If
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,850
Members
449,051
Latest member
excelquestion515

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