简体   繁体   中英

how to extract particular cell to my SQL in EXCEL

Here is a example table in Excel:

ID Name  Account
1  Jon   001
2  Snow  002
3  Alive 003

I want to create a SQL according to account. It looks like,

SELECT * FROM CUSTOMER_TABLE WHERE ACCOUNT=' ';

Is it possible to make system could fulfill ACCOUNT=' ' ? Like system could input each value automatically.

It should like WHERE ACCOUNT='C1', ACCOUNT='C2', ACCOUNT='C3'...

I assume you copied your accounts into a range like Range("E1:E10") . Then you can use a for loop to change accounts for every turn. Change your Query as,

SQL_Query = "Select * From Customer_Table Where Account ="

then try a For Loop .

Dim Query as String
For i = 1 to 10
    Query = SQL_Query & Cells(i,4).value
    'Do your query here.
    'Be careful about that your results should be copied under the last row.
    'Otherwise only the last one will be shown.
Next

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM