Hi,
With sample data it's obvious that my formula is wrong. So discard it.
As the problem with the formula to be inserted by the VBA - look at front and end of sub strings you splitted thye formula ther are incomplete
ActiveCell.FormulaR1C1 = _
"=IF(ISNUMBER( ... ""Interest"",IF" & _
"R(SEARCH(""xero"" ... SEARCH(""unit" & _
"[2])),""Tville Inc"",... ""EP Exp"",""""))))))))))))))))))"
so VBA could not insert such wrong formula
Right notation could be for instance:
ActiveCell.FormulaR1C1 = _
"=IF(ISNUMBER(SEARCH(""coles"",RC[2])),""Groceries"",IF(ISNUMBER(SEARCH(""woolworths"",RC[2])),""Groceries""," & _
"IF(ISNUMBER(SEARCH(""pharmacy"",RC[2])),""Pharmacy"",IF(ISNUMBER(SEARCH(""bupa"",RC[2])),""Health Insurance""," & _
"IF(ISNUMBER(SEARCH(""tcs"",RC[2])),""Hair"",IF(ISNUMBER(SEARCH(""medical"",RC[2])),""Medical""," & _
"IF(ISNUMBER(SEARCH(""interest"",RC[2])),""Interest"",IF(ISNUMBER(SEARCH(""xero"",RC[2])),""Accounting""," & _
"IF(ISNUMBER(SEARCH(""top up"",RC[2])),""CC Exp"",IF(ISNUMBER(SEARCH(""thomas"",RC[2])),""Income""," & _
"IF(ISNUMBER(SEARCH(""telstra"",RC[2])),""Phone"",IF(ISNUMBER(SEARCH(""ep loan"",RC[2])),""EP Exp""," & _
"IF(ISNUMBER(SEARCH(""Tville loan"",RC[2])),""Tville Exp"",IF(ISNUMBER(SEARCH(""ergon"",RC[2])),""Power""," & _
"IF(ISNUMBER(SEARCH(""unit"",RC[2])),""Tville Inc"",IF(ISNUMBER(SEARCH(""car"",RC[2])),""Car Exp""," & _
"IF(ISNUMBER(SEARCH(""townsville city"",RC[2])),""Tville Exp"",IF(ISNUMBER(SEARCH(""LSC"",RC[2])),""EP Exp"",""""))))))))))))))))))"
Having sample file available, I can propose such (sample - may be not most effective, but I hope easy to read) code to do this without formulas.
Sub fill_with_descriptions()
Const keywordslist = "coles,woolworths,pharmacy,bupa"
Const descriptionslist = "Groceries,Groceries,Pharmacy,Health Insurance"
Dim i As Integer, cell As Range, keyword As Variant, description As Variant
keyword = Split(keywordslist, ",")
description = Split(descriptionslist, ",")
If UBound(keyword) <> UBound(description) Then
MsgBox "Number of items in keywords and descriptions lists differ", vbCritical
Exit Sub
End If
Application.ScreenUpdating = False
For Each cell In Range(Range("F1"), Cells(Rows.Count, "F").End(xlUp))
For i = LBound(keyword) To UBound(keyword)
If InStr(1, cell, keyword(i), vbTextCompare) <> 0 Then
cell.Offset(0, -2) = description(i)
Exit For 'if found do not check other possibilities
End If
Next i
Next cell
End Sub
Bookmarks