Worksheet_Change problem

liampog

Active Member
Joined
Aug 3, 2010
Messages
316
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi there

I'm trying to enter the following code into my Worksheet_Change SUB but it doesn't work properly:

Code:
If Target.Offset(0, -1).Text = "*[Insp]*" Then
    Range(ActiveCell.Offset(0, 1), ActiveCell.Offset(0, 37)).Interior.ColorIndex = 24
    Else: Range(ActiveCell.Offset(0, 1), ActiveCell.Offset(0, 37)).Interior.Color = xlNone
End If

Basically, when the cell to the direct left of the Target cell contains [Insp] anywhere in the cell I want it to colour the cells to the right of the Target cell... but I don't know how to include wildcards in this.

I tried with the asterisks (*) but it's not working.

Any suggestions? I'm sure it can be done, but I don't know how.

Thanks in advance for the help.

Liam
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Maybe this :

If InStr(1, Target.Offset(0, -1).Text, "[Insp]", vbTextCompare) Then
 
Upvote 0
Works perfectly!

Thanks so much for the speedy reply!

Liam
 
Upvote 0
Hi there

I'm trying to enter the following code into my Worksheet_Change SUB but it doesn't work properly:

Code:
If Target.Offset(0, -1).Text = "*[Insp]*" Then
    Range(ActiveCell.Offset(0, 1), ActiveCell.Offset(0, 37)).Interior.ColorIndex = 24
    Else: Range(ActiveCell.Offset(0, 1), ActiveCell.Offset(0, 37)).Interior.Color = xlNone
End If

Basically, when the cell to the direct left of the Target cell contains [Insp] anywhere in the cell I want it to colour the cells to the right of the Target cell... but I don't know how to include wildcards in this.

I tried with the asterisks (*) but it's not working.

Any suggestions? I'm sure it can be done, but I don't know how.

Thanks in advance for the help.

Liam

I tried this and it might work

when the cell to the direct left of the Target cell contains [Insp] anywhere in the cell, I want it to colour the cells to the right of the Target cell

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Offset(, -1).Value Like "*[[]Insp]*" Then
        Target.Offset(, 1).Resize(, 37).Interior.ColorIndex = 24
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,541
Messages
6,179,418
Members
452,912
Latest member
alicemil

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