Mavericks334
Active Member
- Joined
- Jan 26, 2011
- Messages
- 280
Hi,
Below is my macro that i use to Create a sheet if the sheet does not exist and the copy the data and paste it. Then the macro goes to the pivot table sheet and copies all the information according to the filter.
After the sheet is created and even if there is no data the macro check for the pivot table inform (This code could be improved).
Since there is no pivot table data it gives me an error. When i create a condition to skip the copy if there is not data and avoid creating a sheet.
I get an error when i go to the next sheet to repeat the process.
' Hold Reqs Update<o
></o
>
On Error Resume Next<o
></o
>
sh = Sheets("Hold Reqs").Name<o
></o
>
On Error GoTo 0<o
></o
>
If sh <> "" Then<o
></o
>
Sheets(sh).Activate<o
></o
>
Else<o
></o
>
Worksheets.Add.Name = "Hold Reqs"<o
></o
>
End If <o
></o
>
Sheets("Hold Reqs").Select<o
></o
>
ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=2<o
></o
>
Range("A1").Select<o
></o
>
Range(Selection, Selection.End(xlToRight)).Select<o
></o
>
Range(Selection, Selection.End(xlDown)).Select<o
></o
>
Selection.ClearContents<o
></o
>
Lw = Range("A" & Rows.Count).End(xlUp).Row<o
></o
>
Range("Y2").Select<o
></o
>
Range("Y2:Z2" & Lw).Select<o
></o
>
Range(Selection, Selection.End(xlDown)).Select<o
></o
>
Selection.ClearContents<o
></o
>
Windows("FTS_HC").Activate<o
></o
>
Sheets("HR").Select<o
></o
>
Lw = Range("A" & Rows.Count).End(xlUp).Row<o
></o
>
<o
> </o
>
Range("A1").Select<o
></o
>
Range("A1").AutoFilter Field:=25, Criteria1:= _<o
></o
>
"IO"<o
></o
>
Range("A1:W" & Lw).Select<o
></o
>
Range(Selection, Selection.End(xlDown)).Select<o
></o
>
Selection.Copy<o
></o
>
Windows(fname).Activate<o
></o
>
Sheets("Hold Reqs").Select<o
></o
>
Range("A1").Select<o
></o
>
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _<o
></o
>
:=False, Transpose:=False <o
></o
>
Windows("FTS_HC").Activate<o
></o
>
Sheets("Pivot_HR").Select <o
></o
>
ActiveSheet.PivotTables("PivotTable4").PivotFields("Function"). _<o
></o
>
ClearAllFilters<o
></o
>
ActiveSheet.PivotTables("PivotTable4").PivotFields("Sub_function"). _<o
></o
>
ClearAllFilters<o
></o
>
ActiveSheet.PivotTables("PivotTable3").PivotFields("Function").CurrentPage = _<o
></o
>
"IO"<o
></o
>
Lw = Range("a" & Rows.Count).End(xlUp).Row<o
></o
>
<o
> </o
>
Range("a6").Select<o
></o
>
With ActiveSheet.PivotTables("PivotTable4").PivotFields("Dept ID")<o
></o
>
.PivotItems("(blank)").Visible = False<o
></o
>
End With <o
></o
>
Range("a6").Select<o
></o
>
Range("a6:b" & Lw).Select<o
></o
>
Range(Selection, Selection.End(xlDown)).Select<o
></o
>
Selection.Copy<o
></o
>
Windows(fname).Activate<o
></o
>
Range("Y2").Select<o
></o
>
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _<o
></o
>
:=False, Transpose:=False<o
></o
>
ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=1<o
></o
>
Rows("1:1").Select<o
></o
>
For Each ws In ActiveWorkbook.Worksheets<o
></o
>
Application.DisplayAlerts = False<o
></o
>
If LenB(ActiveSheet.Range("A2")) = 0 Then ActiveSheet.Delete<o
></o
>
Application.DisplayAlerts = True<o
></o
>
Next ws<o
></o
>
' Transfer in Update<o
></o
>
On Error Resume Next<o
></o
>
sh = Sheets("Transfers In").Name<o
></o
>
On Error GoTo 0<o
></o
>
If sh <> "" Then<o
></o
>
Sheets(sh).Activate<o
></o
>
Else<o
></o
>
Worksheets.Add.Name = "Transfers In"<o
></o
>
End If
The grey areas are where the error occurs if i say on Error resume next the send grey area the sheet name does not change.
Below is my macro that i use to Create a sheet if the sheet does not exist and the copy the data and paste it. Then the macro goes to the pivot table sheet and copies all the information according to the filter.
After the sheet is created and even if there is no data the macro check for the pivot table inform (This code could be improved).
Since there is no pivot table data it gives me an error. When i create a condition to skip the copy if there is not data and avoid creating a sheet.
I get an error when i go to the next sheet to repeat the process.
' Hold Reqs Update<o
On Error Resume Next<o
sh = Sheets("Hold Reqs").Name<o
On Error GoTo 0<o
If sh <> "" Then<o
Sheets(sh).Activate<o
Else<o
Worksheets.Add.Name = "Hold Reqs"<o
End If <o
Sheets("Hold Reqs").Select<o
ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=2<o
Range("A1").Select<o
Range(Selection, Selection.End(xlToRight)).Select<o
Range(Selection, Selection.End(xlDown)).Select<o
Selection.ClearContents<o
Lw = Range("A" & Rows.Count).End(xlUp).Row<o
Range("Y2").Select<o
Range("Y2:Z2" & Lw).Select<o
Range(Selection, Selection.End(xlDown)).Select<o
Selection.ClearContents<o
Windows("FTS_HC").Activate<o
Sheets("HR").Select<o
Lw = Range("A" & Rows.Count).End(xlUp).Row<o
<o
Range("A1").Select<o
Range("A1").AutoFilter Field:=25, Criteria1:= _<o
"IO"<o
Range("A1:W" & Lw).Select<o
Range(Selection, Selection.End(xlDown)).Select<o
Selection.Copy<o
Windows(fname).Activate<o
Sheets("Hold Reqs").Select<o
Range("A1").Select<o
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _<o
:=False, Transpose:=False <o
Windows("FTS_HC").Activate<o
Sheets("Pivot_HR").Select <o
ActiveSheet.PivotTables("PivotTable4").PivotFields("Function"). _<o
ClearAllFilters<o
ActiveSheet.PivotTables("PivotTable4").PivotFields("Sub_function"). _<o
ClearAllFilters<o
ActiveSheet.PivotTables("PivotTable3").PivotFields("Function").CurrentPage = _<o
"IO"<o
Lw = Range("a" & Rows.Count).End(xlUp).Row<o
<o
Range("a6").Select<o
With ActiveSheet.PivotTables("PivotTable4").PivotFields("Dept ID")<o
.PivotItems("(blank)").Visible = False<o
End With <o
Range("a6").Select<o
Range("a6:b" & Lw).Select<o
Range(Selection, Selection.End(xlDown)).Select<o
Selection.Copy<o
Windows(fname).Activate<o
Range("Y2").Select<o
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _<o
:=False, Transpose:=False<o
ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=1<o
Rows("1:1").Select<o
For Each ws In ActiveWorkbook.Worksheets<o
Application.DisplayAlerts = False<o
If LenB(ActiveSheet.Range("A2")) = 0 Then ActiveSheet.Delete<o
Application.DisplayAlerts = True<o
Next ws<o
' Transfer in Update<o
On Error Resume Next<o
sh = Sheets("Transfers In").Name<o
On Error GoTo 0<o
If sh <> "" Then<o
Sheets(sh).Activate<o
Else<o
Worksheets.Add.Name = "Transfers In"<o
End If
The grey areas are where the error occurs if i say on Error resume next the send grey area the sheet name does not change.