Bill Roberts
New Member
- Joined
- Aug 7, 2019
- Messages
- 3
Greetings,
I have a spreadsheet with names and addresses. In the name column, I need to compare all the words to a fixed list of terms, such as "borrower", "homeowner", "LLC", etc. I will be highlighting the row to look at individually. So far, I can get the code to work, but with only one term, in this case: "BORROWER". I attempted to make an array with the list of words that would trigger highlighting the row, but that doesn't work. I get a type mismatch. Both versions of the code are here:
******************************************************************************************
Sub HighlightRenters()
Dim lastrow As Long, i As Integer, icount As Integer, sArray As Variant, noown As Variant
With ActiveSheet
lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
End With
sArray = Array("BORROWER", "HOMEOWNER")
With ActiveSheet
For x = 1 To lastrow
If InStr(1, LCase(Range("F" & x)), "BORROWER", vbTextCompare) <> 0 Then
Rows(x).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
' icount = icount + 1
' Range("H" & icount & ":L" & icount) = Range("A" & i & ":E" & i).Value
End If
Next x
End With
End Sub
***********************************************************************************
Okay that colors the rows with "Borrower" contained in the words in the F column.
Here is what I am trying using an array:
************************************************************************************
Sub HighlightRenters()
Dim lastrow As Long, i As Integer, icount As Integer, sArray As Variant, renter As Variant
With ActiveSheet
lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
End With
sArray = Array("BORROWER", "HOMEOWNER","LLC")
renter = Split(sArray, ",")
With ActiveSheet
For x = 1 To lastrow
If InStr(1, LCase(Range("F" & x)), renter, vbTextCompare) <> 0 Then (This is the line with the type mismatch)
Rows(x).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Next x
End With
End Sub
**************************************************************************
Any advice will be appreciated.
Bill
I have a spreadsheet with names and addresses. In the name column, I need to compare all the words to a fixed list of terms, such as "borrower", "homeowner", "LLC", etc. I will be highlighting the row to look at individually. So far, I can get the code to work, but with only one term, in this case: "BORROWER". I attempted to make an array with the list of words that would trigger highlighting the row, but that doesn't work. I get a type mismatch. Both versions of the code are here:
******************************************************************************************
Sub HighlightRenters()
Dim lastrow As Long, i As Integer, icount As Integer, sArray As Variant, noown As Variant
With ActiveSheet
lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
End With
sArray = Array("BORROWER", "HOMEOWNER")
With ActiveSheet
For x = 1 To lastrow
If InStr(1, LCase(Range("F" & x)), "BORROWER", vbTextCompare) <> 0 Then
Rows(x).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
' icount = icount + 1
' Range("H" & icount & ":L" & icount) = Range("A" & i & ":E" & i).Value
End If
Next x
End With
End Sub
***********************************************************************************
Okay that colors the rows with "Borrower" contained in the words in the F column.
Here is what I am trying using an array:
************************************************************************************
Sub HighlightRenters()
Dim lastrow As Long, i As Integer, icount As Integer, sArray As Variant, renter As Variant
With ActiveSheet
lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
End With
sArray = Array("BORROWER", "HOMEOWNER","LLC")
renter = Split(sArray, ",")
With ActiveSheet
For x = 1 To lastrow
If InStr(1, LCase(Range("F" & x)), renter, vbTextCompare) <> 0 Then (This is the line with the type mismatch)
Rows(x).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Next x
End With
End Sub
**************************************************************************
Any advice will be appreciated.
Bill