Hi folks,
Wonder if anyone can offer a suggestion(s) as to get this to run quicker please, as taking an age and the sheet is only about 1,000 rows at the moment. I'm using Excel 2013 if it makes a difference.
The search columns, O and AD can contain just the name, or lots of text with the name at start, end or in middle, and could have more than one name in them. They are free text columns, so can contain pretty much anything, hence I need to check the whole contents to see if the names are somewhere within it (ie can't do cell value etc).
Obviously if there is a less onerous way to achieve the same results, I'm open to those, this is just the only way I could think of/get working as hardly use vba anymore and I can't remember jack!
Cheers all, Upex
Wonder if anyone can offer a suggestion(s) as to get this to run quicker please, as taking an age and the sheet is only about 1,000 rows at the moment. I'm using Excel 2013 if it makes a difference.
The search columns, O and AD can contain just the name, or lots of text with the name at start, end or in middle, and could have more than one name in them. They are free text columns, so can contain pretty much anything, hence I need to check the whole contents to see if the names are somewhere within it (ie can't do cell value etc).
Obviously if there is a less onerous way to achieve the same results, I'm open to those, this is just the only way I could think of/get working as hardly use vba anymore and I can't remember jack!
Cheers all, Upex
Code:
Sub Highlight_Left_Columns()
'Adds a 'Yes' in columns A-H for each row to identify if the respective search text is found within each rows O or AD column as part of the cells contents (sole entry or within its string)
Application.ScreenUpdating = False
Dim lngI As Integer
For lngI = 2 To Cells.SpecialCells(xlCellTypeLastCell).Row
If InStr(1, Range("O" & lngI).Value, "Alex", vbTextCompare) Then
Range("A" & lngI).Value = "Yes"
If InStr(1, Range("O" & lngI).Value, "Brian", vbTextCompare) Then
Range("b" & lngI).Value = "Yes"
If InStr(1, Range("O" & lngI).Value, "Claire", vbTextCompare) Then
Range("c" & lngI).Value = "Yes"
If InStr(1, Range("O" & lngI).Value, "Darren", vbTextCompare) Then
Range("d" & lngI).Value = "Yes"
If InStr(1, Range("O" & lngI).Value, "Erica", vbTextCompare) Then
Range("e" & lngI).Value = "Yes"
If InStr(1, Range("O" & lngI).Value, "Francis", vbTextCompare) Then
Range("f" & lngI).Value = "Yes"
If InStr(1, Range("O" & lngI).Value, "Gary", vbTextCompare) Then
Range("g" & lngI).Value = "Yes"
If InStr(1, Range("O" & lngI).Value, "Harry", vbTextCompare) Then
Range("h" & lngI).Value = "Yes"
End If
End If
End If
End If
End If
End If
End If
End If
If InStr(1, Range("AD" & lngI).Value, "Alex", vbTextCompare) Then
Range("A" & lngI).Value = "Yes"
If InStr(1, Range("AD" & lngI).Value, "Brian", vbTextCompare) Then
Range("b" & lngI).Value = "Yes"
If InStr(1, Range("AD" & lngI).Value, "Claire", vbTextCompare) Then
Range("c" & lngI).Value = "Yes"
If InStr(1, Range("AD" & lngI).Value, "Darren", vbTextCompare) Then
Range("d" & lngI).Value = "Yes"
If InStr(1, Range("AD" & lngI).Value, "Erica", vbTextCompare) Then
Range("e" & lngI).Value = "Yes"
If InStr(1, Range("AD" & lngI).Value, "Francis", vbTextCompare) Then
Range("f" & lngI).Value = "Yes"
If InStr(1, Range("AD" & lngI).Value, "Gary", vbTextCompare) Then
Range("g" & lngI).Value = "Yes"
If InStr(1, Range("AD" & lngI).Value, "Harry", vbTextCompare) Then
Range("h" & lngI).Value = "Yes"
End If
End If
End If
End If
End If
End If
End If
End If
Next lngI
'Application.ScreenUpdating = True
End Sub
Last edited: