Hello, I am very new to VBA and any help would be appreciated.
The purpose of this code is to reformat one pivot table upon a change on the same worksheet only. I have placed the code in the individual worksheet object. It works perfectly EXCEPT when I refresh a pivot table on a separate sheet I receive a ‘Run-time Error ‘1004’ Select Method of Range class Failed message.
The line that is highlighted in the debugger is after the interest line “Range("D9:L9").Select”. There will be very light VBA in this workbook and any ugly fix will work. Even something similar to an “IFERROR” that simply exits the sub. I’m confused as to why the sub is even activated if I am on a separate worksheet. Thank you!
The purpose of this code is to reformat one pivot table upon a change on the same worksheet only. I have placed the code in the individual worksheet object. It works perfectly EXCEPT when I refresh a pivot table on a separate sheet I receive a ‘Run-time Error ‘1004’ Select Method of Range class Failed message.
The line that is highlighted in the debugger is after the interest line “Range("D9:L9").Select”. There will be very light VBA in this workbook and any ugly fix will work. Even something similar to an “IFERROR” that simply exits the sub. I’m confused as to why the sub is even activated if I am on a separate worksheet. Thank you!
Code:
Private Sub Worksheet_Change(ByVal Target As Range) Application.ScreenUpdating = False
Dim Rng As Range
Set Rng = Intersect(Target, Range("A10:M500"))
Range("D9:L9").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("M9").Select
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("D:L").Select
Selection.ColumnWidth = 16
Range("A1").Select
End Sub