Results 1 to 1 of 1

Screen fails to redraw (sheets overlapping) after executing a macro, errHandler problem?

Threaded View

  1. #1
    Registered User
    Join Date
    06-19-2015
    Location
    Bogota
    MS-Off Ver
    Officce 365
    Posts
    54

    Screen fails to redraw (sheets overlapping) after executing a macro, errHandler problem?

    Hi friends,

    I am almost there with my tool but it's not working properly. After I play the following macro the screen doesn't refresh properly when I change a cell. Just imagine that some parts of different sheets are showed overlapped in the active sheet.

    If I scroll down everything get back to normality until I again need to change a cell.

    Sub Extractor()
    '
    ' byYearExtractor Macro
    '
        Dim i As Integer
        Dim n As Integer
        Dim Range2 As Range, Range1 As Range
        Dim Source As String, Destiny As String, TableName As String, AdditionalColumn As String
        Dim UniqueDestinyArray As Variant, FullDestinyArray As Variant
        Dim flagsSource As Boolean, flagDestiny As Boolean, flagLoadTable As Boolean
        
        Dim ws As Worksheet
        
        'On Error GoTo errHandler
        Application.Calculation = xlCalculationManual
        Application.ScreenUpdating = False
        Application.DisplayStatusBar = False
        Application.EnableEvents = False
        
        Set ws = ActiveSheet
        
        Call UNPROTECT_SHEETS
        
        If Sheets("LoadTable").Visible = False Then flagLoadTable = True
        If Sheets("LoadTable").Visible = False Then Sheets("LoadTable").Visible = True
        
        Sheets("LoadTable").Select
        
        'Clear columns F (No. of columns)and D (Table name)
        Range("F2:F999").ClearContents
        Range("D2:D999").ClearContents
        
        Range("A1").Select
        
        NumRows = Range("A1", Range("A1").End(xlDown)).Rows.Count - 1
        
        If NumRows = 0 Or NumRows > 1000 Then
        MsgBox ("insert a table to load or less than 500 tables")
        Exit Sub
        End If
            
        
        'Clear tables in Destiny Sheets
        FullDestinyArray = Range("E2", Range("E2").End(xlDown))
        UniqueDestinyArray = UniqueItems(FullDestinyArray, False)
        
        For i = LBound(UniqueDestinyArray) + 1 To UBound(UniqueDestinyArray)
        Destiny = UniqueDestinyArray(i)
        
        If Sheets(Destiny).Visible = False Then flagDestiny = True
        If Sheets(Destiny).Visible = False Then Sheets(Destiny).Visible = True
    
        Sheets(Destiny).Select
        Range("A2:ZZ65563").ClearContents
        Range("A2").Select
        
        Next
        
        'Load tables
        Sheets("LoadTable").Select
        Range("A2").Select
        For i = 0 To NumRows - 1
            Do While ActiveCell(i + 1, 8).Value = "NO"
            i = i + 1
            Loop
            
            If ActiveCell(i + 1, 8).Value = "YES" Then
            
            'if the line lacks of data, exit
            Set Range1 = ActiveCell(i + 1, 2)
            If Range1 = "" Then
                MsgBox "Complete initial cell"
                Exit Sub
            End If
            
            Set Range2 = ActiveCell(i + 1, 3)
            If Range2 = "" Then
                MsgBox "Complete ending cell"
                Exit Sub
            End If
            
            Source = ActiveCell(i + 1, 1)
            If Source = "" Then
                MsgBox "Complete sources"
                Exit Sub
            End If
            
            Destiny = ActiveCell(i + 1, 5)
            If Destiny = "" Then
                MsgBox "Complete destinations"
                Exit Sub
            End If
            
            'No of columns
            ActiveCell(i + 1, 4).Value = Range(Range1 & ":" & Range2).Columns.Count
            numberColumns = Range(Range1 & ":" & Range2).Columns.Count
            
            'No of rows
            numberRows = Range(Range1 & ":" & Range2).Rows.Count
                    
            'Optional column
            AdditionalColumn = ActiveCell(i + 1, 7)
            
            If Sheets(Source).Visible = False Then flagSource = True
            If Sheets(Source).Visible = False Then Sheets(Source).Visible = True
                    
            'Get table name
            'Sheets(Source).Select
            TableName = Sheets(Source).Range(Range1).Offset(-1, 0)
            Sheets(Source).Range(Range1).Offset(-1, 0).Copy
            'Sheets("LoadTable").Select
            ActiveCell(i + 1, 6).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            
                
            'Get data table
            Sheets(Source).Range(Range1 & ":" & Range2).Copy
            
            If Sheets(Destiny).Visible = False Then flagDestiny = True
            If Sheets(Destiny).Visible = False Then Sheets(Destiny).Visible = True
            
            Sheets(Destiny).Select
            Range("B65536").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            Application.CutCopyMode = False
            
            Range("A65536").End(xlUp).Activate
               
                For n = 0 To Range(Range1 & ":" & Range2).Rows.Count - 1
                ActiveCell.Offset(n + 1, 0).Value = TableName
                Next
            
                            
            'If AdditionalColumn <> "" Then Range("A1").End(xlDown).End(xlToRight).Offset(0, 1).End(xlUp).Activate
            If AdditionalColumn <> "" Then
                Range("A1").End(xlDown).Offset(-numberRows, numberColumns + 1).Select
                For Z = 0 To Range(Range1 & ":" & Range2).Rows.Count - 1
                ActiveCell.Offset(Z + 1, 0).Value = AdditionalColumn
                Next
            End If
            
            AdditionalColumn = ""
            
            Range("A1").Select
            
            If flagSource = True Then Sheets(Source).Visible = False
            If flagSource = True Then flagSource = False
            
            If flagDestiny = True Then Sheets(Destiny).Visible = False
            If flagDestiny = True Then flagDestiny = False
            
            Sheets("LoadTable").Select
            Range("A2").Select
        
        End If
        
        Next
        
        If flagLoadTable = True Then Sheets("LoadTable").Visible = False
        If flagLoadTable = True Then flagLoadTable = False
        
        'Sheets("LoadTable").Select
        'Call AdjustPivotDataRange
        Call SHOW_PIVOTTABLE
        
        Sheets("HOMEPAGE").Select
        Range("K19").Select
        Call UnrestrictPivotTable
        
        Call RefreshAll
        
        Call RestrictPivotTable
    
        Range("A1").Select
           
    'errHandler:
    '    Application.ScreenUpdating = True
        Application.Calculation = xlCalculationAutomatic
        Application.DisplayStatusBar = True
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    
        Call HIDE_COLLATIONSHEETS
        Call PROTECT_SHEETS
        ws.Activate
        
            
    End Sub
    I am pretty sure there is an error in the execution because when line "On Error GoTo errHandler" was working before I commented but I don't know what it means or how to take advantage of it.

    Hope you can help me. It's the final issue I need to solve out.

    Many thanks. All the best,
    Geronimo

    ps: this is a split up of this post because it became too large to follow http://www.excelforum.com/excel-prog...ns-manual.html
    Last edited by gerotutu; 08-04-2015 at 08:04 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro fails to work across multiple sheets
    By nihargoel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-27-2015, 08:15 AM
  2. Updating log on screen fails
    By jtable in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-26-2013, 06:06 AM
  3. renaming sheets macro fails
    By fatpiggy123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-27-2010, 10:18 AM
  4. template macro executing problem the 2nd time
    By MAB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-25-2006, 08:10 AM
  5. Remove screen 'flicker' on executing code
    By peter.thompson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-07-2006, 04:35 AM
  6. Macro fails after screen is locked or screensaver becomes active
    By Denham in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-14-2005, 07:05 PM
  7. Problem executing a macro from different workbook where it is
    By Sergio Calleja in forum Excel General
    Replies: 1
    Last Post: 01-17-2005, 09:06 AM

Tags for this Thread

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