+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    09-29-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    77

    Unhide sheet, calculate and hide

    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

  2. #2
    Forum Guru Domski's Avatar
    Join Date
    12-14-2009
    Location
    Leeds, UK
    MS-Off Ver
    2003 (work), 2007 & 2010 (home)
    Posts
    3,517

    Re: Unhide sheet, calculate and hide

    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.

  3. #3
    Registered User
    Join Date
    09-29-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    77

    Re: Unhide sheet, calculate and hide

    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

  4. #4
    Forum Guru Domski's Avatar
    Join Date
    12-14-2009
    Location
    Leeds, UK
    MS-Off Ver
    2003 (work), 2007 & 2010 (home)
    Posts
    3,517

    Re: Unhide sheet, calculate and hide

    Sorry, got to go to a meeting but the basic premise around looping through the worksheets in a workbook is like this:

    Code:
    Sub Loop_Sheets()
    
    Dim ws As Worksheet
    
    For Each ws In ThisWorkbook.Worksheets
    
        MsgBox ws.Name
        
    Next ws
    
    End Sub
    Hope that makes some sense, will try and have a look at your code later.

    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0