I'm trying to take a specific column range (B2:B500), check if the cell contains certain text string combinations and if it contains the combinations output a 'x' into a specific column which is depending on the text string in column B. My VBA isn't populating the 'x' into any columns, and I can't identify why.
Sub replace()
With Worksheets("Dave Edit") 'Change to your worksheet
Dim i As Integer
For i = 2 To 500
Select Case .Range("B" & i)
Case Like "*AR*"
.Range("M" & i).Value = "x"
Case Like "*FA*"
.Range("L" & i).Value = "x"
End Select
Next i
End With
End Sub
The code runs without error, but I get no output. Also, if you know how I need to make when column B contains both also populate. However, I can go manually check the VBA later to fix that, the current issue is more important.
CodePudding user response:
Your Select Case
is a little off and it is always better to set the worksheet, just in case the active sheet is not the one you expect:
Sub x()
With Worksheets("Sheet1") 'Change to your worksheet
Dim i As Integer
For i = 2 To 500
Select Case True
Case .Range("B" & i) Like "*AR*"
.Range("M" & i).Value = "x"
Case .Range("B" & i) Like "*FA*"
.Range("L" & i).Value = "x"
End Select
Next i
End With
End Sub