There have been a few posts about this, but cannot find anything relating specifically to my problem.
I want to have a WHERE search on a named range within VBA where the range is changeable e.g not simply A1:A10, but A1:End
I have tried the below, but only the last cell within the range is used in the SQL WHERE results
Set Brokers = Sheets("Brokers").Range("A2").End(xlDown)
Dim r As Variant
r = Brokers.Value
....
WHERE c_broker = '" & r & "'"
I have also tried the below, but am getting a "type mismatch" error
WHERE c_broker IN( '" & Join(Application.Transpose(Sheets("Brokers").Range("A2").End(xlDown).Value), "','") & "')"
If anyone could help - or let me know if not possible at all - that would be great!
Thanks!
EDIT: To further explain this, I have a range in sheet "Brokers" starting from A2 going down where the end can change depending on user input e.g it can be A2:A10 or A2:A15. I want SQL to pick up on this range at whatever it currently is, which is why I've been trying to use End(xlDown) in the VBA. I have tried changing the above to the below, but am having an "Application-defined or object-defined error"....the same goes when I add this in the SQL WHERE line - unless I am doing something incorrect with the below?
Set Brokers = Sheets("Brokers").Range("A2", Range("A2").End(xlDown))