The code below runs perfectly fine for me, but as I increase the number of rows from hundreds to 70k, the performance degrades to a point where it is not usable. Here is my code.
'Find the last non-blank cell in column A(1)
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Set rng = Range("A2:A" & LastRow)
For Each cell In rng
myRange = myRange & "'" & cell.Value & "'" & ","
Next cell
' remove last comma from concatenated string
myRange = Left(myRange, Len(myRange) - 1)
'This is your actual MS SQL query that you need to run; you should check this query first using a more robust SQL editor (such as HeidiSQL) to ensure your query is valid
StrQuery = "SELECT * FROM myTable Where BB_ID IN (" & myRange & ") AND myDate < '12/11/2019';"
'Performs the actual query
rst.Open StrQuery, cnn
'Dumps all the results from the StrQuery into cell A2 of the first sheet in the active workbook
Worksheets("Sheet1").Range("A2").CopyFromRecordset rst
How can I take a list of IDs in ColumnA and VERY QUICKLY convert it to comma-delimited string so I can feed it into a SQL query? Thanks.