Use of wild cards

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello, I havea basic macro and it does work; however, I need to use a wilde card "*" and it doesn't work. After DEP and ARR I need a wild card. In Column one it will always begin with a DEP or ARR. Lastly I would like those colors to extend through Column F.

My macro is:
VBA Code:
Sub Local_BACKGROUND()
    Sheets("Schedule").Select
    endrow = Range("A" & Rows.count).End(xlUp).Row
    
    For Each cell In Range("A1:A" & endrow)
        Select Case cell.Value
            Case "DEP"
            Range(Cells(cell.Row, "A"), Cells(cell.Row, "A")).Interior.ColorIndex = 35
            Case "ARR"
            Range(Cells(cell.Row, "A"), Cells(cell.Row, "A")).Interior.ColorIndex = 22
            End Select
    Next cell
End Sub
 

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 Livin, since all cells will always begin with DEP or ARR, then you could change the cell.value to only look at the first three characters using the LEFT function.

Select Case Left(cell.Value, 3)
 
Upvote 0
Solution
If you were to have differing lengths of strings, another way to do this is:

Code:
Select Case True
            cell.value like "DEP*"
            Range(Cells(cell.Row, "A"), Cells(cell.Row, "A")).Interior.ColorIndex = 35
            cell.value like "ARR*"
            Range(Cells(cell.Row, "A"), Cells(cell.Row, "A")).Interior.ColorIndex = 22
End Select
 
Upvote 0
Hi Livin, since all cells will always begin with DEP or ARR, then you could change the cell.value to only look at the first three characters using the LEFT function.

Select Case Left(cell.Value, 3)
Thank you so much, That part worked, how can I get the cell fill to go through Column F.?
 
Upvote 0
Thank you so much, That part worked, how can I get the cell fill to go through Column F.?
You currently have it going from column A to column A:
Rich (BB code):
Range(Cells(cell.Row, "A"), Cells(cell.Row, "A")).Interior.ColorIndex = 35

Just update it to go from A to F:
Rich (BB code):
Range(Cells(cell.Row, "A"), Cells(cell.Row, "F")).Interior.ColorIndex = 35
 
Upvote 0
You currently have it going from column A to column A:
Rich (BB code):
Range(Cells(cell.Row, "A"), Cells(cell.Row, "A")).Interior.ColorIndex = 35

Just update it to go from A to F:
Rich (BB code):
Range(Cells(cell.Row, "A"), Cells(cell.Row, "F")).Interior.ColorIndex = 35
Spot on- thank you!
 
Upvote 0

Forum statistics

Threads
1,214,586
Messages
6,120,402
Members
448,958
Latest member
Hat4Life

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