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
Bookmarks