0

I am trying to write a macro that queries the SQL database but enters a condition into the query. That condition is a range of values in a column in the spreadsheet.

So, I have "Sheet1", where column A is titled "code" with values from A2 onwards. I want to run a SQL query that says:

SELECT value FROM dbtable WHERE code = 'ValueFromA2'

With the result being populated in cell B2.

I then need to continue that query down through B3, B4, etc. until it's reached the end of the range of values in column A.

Is this possible?

jarlh
  • 42,561
  • 8
  • 45
  • 63
GilesV
  • 11
  • 2

1 Answers1

0
  1. Use Excel to create list of queries into the new column by concatenating your SQL logic with "code" values.

    See this example: https://stackoverflow.com/a/16819629/327165

  2. Use VBA to loop thru column with SQL queries and populate results into column B. As an option you can create queries in VBA.

    See this example: SQL query in VBA, code stored in several cells in Excel

Ilya Berdichevsky
  • 1,249
  • 10
  • 24