VBA to read from Database?

zlac017

New Member
Joined
Sep 1, 2005
Messages
3
Hi, I'm quite new to excel macro/vba programming and need some guidence.

I need to write a macro that will (probably) use an ODBC DSN to connect to a database and select two columns COLA and COLB from TABLE1. I want it to place the contents of COLA into column A in my spreadsheet and COLB in column B in my spreadsheet.

Does this sound possibble? if so could anyone give me a good starting point?

I have already created an ODBC connection within Windows - is it possible to use this?

Thank you very much in advance.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
As with most VBA the best idea is to start by recording a macro of the process as you do the job manually. The code can then be adapted later.

In this case the code may not really be necessary because once we have made the ODBC link it is only necessary to Refresh the data in the worksheet when required.

I usually find that it is best to keep a special sheet for the data alone and link to that for further analysis. That is not an absolute rule, but it does prevent us accidentally doing something that night screw up the Refresh.
 
Upvote 0
And get the data into that sheet by using MS Query via: Data>Import External Data>New Database Query and follow the wizard prompts.

Richard
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top