Forum Discussion
RE_Lax1060
Feb 15, 2023Copper Contributor
Trying to Automate a query
Hi everyone. I have some data that I grab each day from an SQL query and then paste it into a master spreadsheet. Column D is a series of text that I read and then select an appropriate opti...
OliverScheurich
Feb 15, 2023Gold Contributor
=IF(ISNUMBER(SEARCH($B$2,D2)),$A$2,IF(ISNUMBER(SEARCH($B$3,D2)),$A$3,IF(ISNUMBER(SEARCH($B$4,D2)),$A$4,"")))
Is this similar to what you are looking for?
Sub picklist()
Dim i, j, k As Long
Range("E:E").Clear
j = Range("D" & Rows.Count).End(xlUp).Row
For i = 2 To j
For k = 2 To 4
If InStr(Cells(i, 4), Cells(k, 2).Value) Then
Cells(i, 5).Value = Cells(k, 1).Value
Else
End If
Next k
Next i
End Sub
An alternative could be these lines of code. In the attached file you can click the button in cell H2 to run the macro that enters the results in column E.