I have a pretty complex Excel model that has about 25 sheets. The model captures about 300 variables, spread over a few of these sheets. Each of these 300 variables has been named in Excel.
We run this model for different scenarios a couple of times a day and each time we save-as with a new name. As the model is quite large (6 MB's), this is starting to take up quite a bit of space. Another downside, is that it becomes quite difficult to compare different models against eachother.
What I have done is created an access database, and used ADO to pull out all 300 input's from excel and save it to the database. The named range in excel matches exactly to the field name in Access. This works exceptionally well - it only takes about 2-3 seconds to save each model, which I was very happy with. It also makes comparing different scnearios a breeze.
The downside is pulling the data back into Excel - this takes MUCH longer - probably in the region of 40 seconds. The code that I have used to populate excel with the recordset is as follows:
'Open recordset
With rsSite
Set .ActiveConnection = cnn
.Source = "SELECT * from tblSite WHERE [SiteID]=1"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
.MoveFirst
End With
'Populate Excel
Range("Postcode") = rsSite![ProjectName]
Range("Developer") = rsSite![Developer]
Range("RSL") = rsSite![RSL]
Range("LADistrict") = rsSite![LA]
Range("Postcode") = rsSite![PostCode]
Range("ShortAddress") = rsSite![ShortAddress]
I suspect that the issue is that excel has to find the correct field in the recordset AND find the named range and that this is what is taking so long.
Any ideas on how to speed this up, or another approach that I may take?
Thanks for any advice that you can give.
We run this model for different scenarios a couple of times a day and each time we save-as with a new name. As the model is quite large (6 MB's), this is starting to take up quite a bit of space. Another downside, is that it becomes quite difficult to compare different models against eachother.
What I have done is created an access database, and used ADO to pull out all 300 input's from excel and save it to the database. The named range in excel matches exactly to the field name in Access. This works exceptionally well - it only takes about 2-3 seconds to save each model, which I was very happy with. It also makes comparing different scnearios a breeze.
The downside is pulling the data back into Excel - this takes MUCH longer - probably in the region of 40 seconds. The code that I have used to populate excel with the recordset is as follows:
'Open recordset
With rsSite
Set .ActiveConnection = cnn
.Source = "SELECT * from tblSite WHERE [SiteID]=1"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
.MoveFirst
End With
'Populate Excel
Range("Postcode") = rsSite![ProjectName]
Range("Developer") = rsSite![Developer]
Range("RSL") = rsSite![RSL]
Range("LADistrict") = rsSite![LA]
Range("Postcode") = rsSite![PostCode]
Range("ShortAddress") = rsSite![ShortAddress]
I suspect that the issue is that excel has to find the correct field in the recordset AND find the named range and that this is what is taking so long.
Any ideas on how to speed this up, or another approach that I may take?
Thanks for any advice that you can give.