change colour based on wildcard?

Trevor3007

Well-known Member
Joined
Jan 26, 2017
Messages
667
Office Version
  1. 365
Platform
  1. Windows
evening,

i have the code below (it runs within more code, I just extracted & added the 'end sub')

Works great in the workbook that it was originally designed for.








Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
Application.ScreenUpdating = False
    Dim rng As Range
      
    For Each rng In Range("h3:h8000")
        Select Case rng.Value
            Case "Build Completed"
                With Range("A" & rng.Row).Resize(1, 22)
                    .Interior.ColorIndex = 4
                    .Font.Bold = True
                End With
            Case "Swapped-Out"
                With Range("A" & rng.Row).Resize(1, 22)
                    .Interior.ColorIndex = 22
                    .Font.Bold = True
                End With
            Case "Build Started"
                With Range("A" & rng.Row).Resize(1, 22)
                    .Interior.ColorIndex = 6
                    .Font.Bold = True
                End With
            Case "Device Not Received"
                With Range("A" & rng.Row).Resize(1, 22)
                    .Interior.ColorIndex = 28
                    .Font.Bold = True
                End With
            Case "Emailed Requested For SCCM Check"
                With Range("A" & rng.Row).Resize(1, 22)
                    .Interior.ColorIndex = 38
                    .Font.Bold = True
                End With
            Case "Desktop UAD - On Hold ATM"
                With Range("A" & rng.Row).Resize(1, 22)
                    .Interior.ColorIndex = 44
                    .Font.Bold = True
                End With
            Case "Device With Build Engineer"
                With Range("A" & rng.Row).Resize(1, 22)
                    .Interior.ColorIndex = 40
                    .Font.Bold = False
                End With
            Case ""
                With Range("A" & rng.Row).Resize(1, 22)
                    .Interior.ColorIndex = xlNone
                    .Font.Bold = False
                End With
        End Select
    Next rng
    Application.ScreenUpdating = True
    End sub

however, I would wish to use it in another workbook,
Code:
 [COLOR=#ff0000]For Each rng In Range("h3:h8000")
        Select Case rng.Value
            Case "3rd floor engineer door - locked"[/COLOR]

The red text above , is it possible to use a wildcard IE *locked' and it will trigger the colour change?
I tried , but no luck. Hoping someone has the knowledge?


Fingers crossed .
 
thank you once again Dante Amor,

again NO colour, but 'bolds' the entire column????

it must be the laptop I am using as it works fine on my personal laptop.

I will get back to you OK?

You can try a new file, on a new sheet, with new data.
Maybe the sheet has some problems. Try a new book.
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
hi,

I tried it on a completely NEW laptop & still NO colour, but 'bolds' the entire column????

again it works on my personal...wierd eh?
 
Upvote 0
Pretty weird, maybe the excel version


perhaps? its office 2010....

i have this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A:A")) Is Nothing Then
        If Target.Count > 1000 Then Exit Sub
        For Each c In Target
            If LCase(c.Offset(0, 1).Value) = LCase("Matched Assets") Then
                Range("A" & c.Row & ":k" & c.Row).Interior.ColorIndex = 24
            Else
                Range("A" & c.Row & ":k" & c.Row).Interior.ColorIndex = xlNone
            End If
        Next
    End If


which is part of a lot of VB that is on the workbook. Thought, would it be possible to add :-

*locked* = yellow

*call back* = light orange

unsure if the 'wild card would be able to use too?

perhaps you could sort? area applicable would be in the I column BTW
 
Last edited:
Upvote 0
perhaps? its office 2010....

i have this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A:A")) Is Nothing Then
        If Target.Count > 1000 Then Exit Sub
        For Each c In Target
            If LCase(c.Offset(0, 1).Value) = LCase("Matched Assets") Then
                Range("A" & c.Row & ":k" & c.Row).Interior.ColorIndex = 24
            Else
                Range("A" & c.Row & ":k" & c.Row).Interior.ColorIndex = xlNone
            End If
        Next
    End If


which is part of a lot of VB that is on the workbook. Thought, would it be possible to add :-

*locked* = yellow

*call back* = light orange

unsure if the 'wild card would be able to use too?

perhaps you could sort? area applicable would be in the I column BTW

I'm lost.


Do not you use this macro anymore?


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim sh As Worksheet, cases As Variant, colors As Variant, i As Long, lr as long
    Application.ScreenUpdating = False
    If Not Intersect(Target, Range("H:H")) Is Nothing Then
        If Target.Count > 1 Then Exit Sub
        Set sh = ActiveSheet
        If sh.AutoFilterMode Then sh.AutoFilterMode = False
        cases = Array("Build Completed", "Swapped-Out", "Build Started", "Device Not Received", _
                      "Emailed Requested For SCCM Check", "Desktop UAD - On Hold ATM", _
                      "*Engineer*", "*locked*", "")
        
        colrs = Array(4, 22, 6, 28, 38, 44, 40, 5, xlNone)
        lr = sh.range("H" & rows.count).end(xlup).row
        For i = 0 To UBound(cases)
            sh.Range("A2:H" & lr).AutoFilter 8, cases(i)
            sh.AutoFilter.Range.Offset(1).Interior.ColorIndex = colrs(i)
            sh.AutoFilter.Range.Offset(1).Font.Bold = True
        Next
        sh.ShowAllData
    End If
End Sub
 
Upvote 0
I'm lost.


Do not you use this macro anymore?


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim sh As Worksheet, cases As Variant, colors As Variant, i As Long, lr as long
    Application.ScreenUpdating = False
    If Not Intersect(Target, Range("H:H")) Is Nothing Then
        If Target.Count > 1 Then Exit Sub
        Set sh = ActiveSheet
        If sh.AutoFilterMode Then sh.AutoFilterMode = False
        cases = Array("Build Completed", "Swapped-Out", "Build Started", "Device Not Received", _
                      "Emailed Requested For SCCM Check", "Desktop UAD - On Hold ATM", _
                      "*Engineer*", "*locked*", "")
        
        colrs = Array(4, 22, 6, 28, 38, 44, 40, 5, xlNone)
        lr = sh.range("H" & rows.count).end(xlup).row
        For i = 0 To UBound(cases)
            sh.Range("A2:H" & lr).AutoFilter 8, cases(i)
            sh.AutoFilter.Range.Offset(1).Interior.ColorIndex = colrs(i)
            sh.AutoFilter.Range.Offset(1).Font.Bold = True
        Next
        sh.ShowAllData
    End If
End Sub



hello DA,

your code works GREAT on my pers laptop but it does not on my work laptop.

I just had the code that I posted / as shown in my previous.
 
Last edited:
Upvote 0
hello DA,

your code works GREAT on my pers laptop but it does not on my work laptop.

I just had the code that I posted / as shown in my previous.


Maybe, you should go back to the version by pgc01 in post #2
 
Upvote 0

Forum statistics

Threads
1,214,938
Messages
6,122,346
Members
449,080
Latest member
Armadillos

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