Set Dynamic Ranges for data imported from Access

Jameo

Active Member
Joined
Apr 14, 2011
Messages
270
Hi all,

I have a two part question here, forgive my ignorance regarding the intricacies of VBA.

I have an access database set up, this database lists all of the power stations in the country, and associated flow rates, by day and hour.

The power stations are further split into regional areas. So far I have got to the point where a user can select either a region containing multiple stations, a single station, and further filter those results with a date range. I have a make table query that puts the queried data into a new table, and then a cross tab query that formats it into the layout that I require for excel. All these queries are ran from the same command button.

After the cross tab query has been ran, my data lies in the form of:

|Gas Day | Sort Hour | Total Flow Rates | Station 1 Rate | Station 2 Rate |

(this continues for however many stations the user has queried to a max of 30 seperate station columns)

Part 1 - I would now like to import the queried data into an existing excel spreadsheet.

Part 2 - For the imported data I would like to be able to set dynamic named ranges for each column.


My end goal is to be able to automatically generate a series of charts from the newly exported data.

The thing is, I am not totally sure of how to be able to accomplish this. Both the number of rows, and the number of columns will change dependant on the extent of the users query. Also, everytime a new query is made, the old information in the speadsheet must be cleared and the new data added in its place.

From my limited VBA experience I would guess that there would have to be someway to have excel distinguish how many rows of data and colums of data have been added on each query, then set dynamic ranges for each column, and then run a macro designed to plot charts specifically realtde to the amount of columns (i.e. if there are 5 power stations in the list, then plot 5, if there are 10, then plot 10)

I am just clutching at straws a little bit, and don't really know the best way to procede. Any input would be greatly appreciated.

Many thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I realise that the above may not be the easiest post to follow. If you have any further information you wish me to supply please ask.

Ideally my VBA module would look at the data in a query. At the same time as export it would automatically define a dynamic range for each column.

After the data is exported into excel there would then be a futher module that would then create a chart for each defined column
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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