Hi,
I have a spreadsheet that contains 10 hidden sheets, what I'm trying to do is unhide the first sheet, dump some SQL data in there, perform a calculation, hide the sheet and the perform the same routine on Sheet2.
I already have my SQL data being pulled through and the calculation working, I guess what I'm asking for help on is the piece of code that will wrap around this all telling the code to unhide the sheet, hide it again once the calculation as been performed and then move onto the next one and unhide that one. All the way through until there are no more sheets left.
What I'm trying to avoid is copying out the code 10 times and changing sheet names etc.
Thanks in Advance
Can you post the code that you have so far?
Dom
"May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."
If you haven't already please take some time to read the Forum Rules.
Use code tags when posting your VBA code: [code] Your code here [/code]
Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.
Thanks here is the code so far:
Code:Sub GetData() Dim stConn As String, stSQL As String Dim rst As Recordset Dim objConn As ADODB.Connection Dim ConnectionString As String Dim sR As String, sP As String, sC As String Dim i As Integer Dim ws As Worksheet With Application .Calculation = xlAutomatic .EnableEvents = False .ScreenUpdating = False End With ConnectionString = "Database Address" Set objConn = New ADODB.Connection For i = 0 To Sheet1.LB_C1.ListCount - 1 sClass = Sheet1.LB_C1.List(i) sPeril = Sheet1.LB_P1.List(i) sRegion = Sheet1.LB_R1.List(i) stSQL = Code Here If i = 0 Then With objConn .CursorLocation = adUseClient 'Necesary for creating disconnected recordset. .Open ConnectionString 'Instantiate the Recordsetobject and execute the SQL-state. Set rst = .Execute(stSQL) End With End If Sheets("Calculation1").Range("A2").CopyFromRecordset rst Next i objConn.Close Set rst = Nothing Set objConn = Nothing With Application .Calculation = xlAutomatic .EnableEvents = True .ScreenUpdating = True End With End Sub
Sorry, got to go to a meeting but the basic premise around looping through the worksheets in a workbook is like this:
Hope that makes some sense, will try and have a look at your code later.Code:Sub Loop_Sheets() Dim ws As Worksheet For Each ws In ThisWorkbook.Worksheets MsgBox ws.Name Next ws End Sub
Dom
"May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."
If you haven't already please take some time to read the Forum Rules.
Use code tags when posting your VBA code: [code] Your code here [/code]
Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks