I've been trying to get a macro to add a formula to an excel sheet and I have it working if I hardcode the value or use a Long.
However as soon as I try to use a string variable I get "Run-Time error '1004 - Application-defined or object-defined error"
The code below does not throw an error:
And looks like this in the cell
However when i change the third "SearchCol" variable to the string Variable "Search" I get the error:
I can't find what I need to change but its something to do with the string, so I'm guessing I have some syntax wrong or I need to convert the string into something else.
Thanks in advance
However as soon as I try to use a string variable I get "Run-Time error '1004 - Application-defined or object-defined error"
The code below does not throw an error:
VBA Code:
Dim Search As String
Dim SearchCol As Long
Search = "Test"
SearchCol = 1
ActiveCell.Formula2R1C1 = "=UNIQUE(VSTACK(R[" & RowNumber & "]C:R[-1]C,UNIQUE(FILTER('Psoda Data'!R[-39]C[5]:R[4959]C[5],('Psoda Data'!R[-39]C[" & SearchCol & "]:R[4959]C[" & SearchCol & "]=" & SearchCol & ")*('Psoda Data'!R[-39]C[35]:R[4959]C[35]=""Y""),""No Results""))),,TRUE)"
And looks like this in the cell
Excel Formula:
=UNIQUE(VSTACK(F4:F78,UNIQUE(FILTER('Psoda Data'!K40:K5038,('Psoda Data'!D40:D5038=-2)*('Psoda Data'!AO40:AO5038="Y"),"No Results"))),,TRUE)
However when i change the third "SearchCol" variable to the string Variable "Search" I get the error:
VBA Code:
Dim Search As String
Dim SearchCol As Long
Search = "Test"
SearchCol = 1
ActiveCell.Formula2R1C1 = "=UNIQUE(VSTACK(R[" & RowNumber & "]C:R[-1]C,UNIQUE(FILTER('Psoda Data'!R[-39]C[5]:R[4959]C[5],('Psoda Data'!R[-39]C[" & SearchCol & "]:R[4959]C[" & SearchCol & "]=" & Search & ")*('Psoda Data'!R[-39]C[35]:R[4959]C[35]=""Y""),""No Results""))),,TRUE)"
I can't find what I need to change but its something to do with the string, so I'm guessing I have some syntax wrong or I need to convert the string into something else.
Thanks in advance