Results 1 to 3 of 3

Do loop not running

Threaded View

  1. #1
    Registered User
    Join Date
    04-28-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2003
    Posts
    24

    Question Do loop not running

    Hi there

    Appreciate any help as I am building on from this post here
    I have the below bit of code that I want to go through my pivot chart and make the last 7 days of data visible.

    I am having trouble with the Do loop. When I comment out the Do loop it runs okay. When I add the Do loop it dosen’t do the Do loop.

    Can anyone suggest anything?

    Here I am assuming that the date 07/09/2011 is the only date visible in the pivot chart. So when I run this macro the 11/09/2011 will also be visible in the pivot chart.

    When I get the do loop working I hope to have the 11th to the 18th visible( it is still in early stages so a bit of fine tuning needed also)

    Sub ShowAllItems7Days_test()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    Dim objPT As PivotTable
    Dim objPTField As PivotField
    Dim objPTItem As PivotItem
    
    Dim LastDate As Date
    Dim LastDate7 As Date
    
    LastDate = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp)
    LastDate7 = LastDate - 7
    
    MsgBox "LastDate is:" & LastDate & vbCrLf & "LastDate7 is:" & LastDate7 & vbCrLf
    
    For Each ws In Worksheets
    ws.Visible = xlSheetVisible
        For Each objPT In ws.PivotTables
     MsgBox "Pivot table name: " & objPT.Name & vbCrLf & "Sheet name: " & ws.Name & vbCrLf & "test"
                                        
                  'Do Until LastDate7 <= LastDate
                  MsgBox "inside Do"
                    With objPT.PivotFields("date")
                    .PivotItems(LastDate7).Visible = True
                                
                    End With
                   LastDate7 = LastDate7 + 1
                'LastDate = LastDate - 1
               'Loop
        
        MsgBox "LastDate is:" & LastDate & vbCrLf & "LastDate7 is:" & LastDate7 & vbCrLf
              
                
                
                
        Application.ScreenUpdating = True
     
        Next objPT
    Next ws
       
    
       
    End Sub
    Attached Files Attached Files
    Last edited by hattrick_123a; 09-21-2011 at 08:36 PM. Reason: [SOLVED]

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.6.0 RC 1