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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

ravishankar

Well-known Member
Joined
Feb 23, 2006
Messages
3,566
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
 

facethegod

Well-known Member
Joined
Aug 1, 2006
Messages
767
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,357
Office Version
  1. 365
Platform
  1. Windows
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
 

Forum statistics

Threads
1,181,416
Messages
5,929,790
Members
436,694
Latest member
dpatete

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
Top