MayJustQuit
New Member
- Joined
- Jun 19, 2015
- Messages
- 2
I have a workbook where it is normal for rows and columns to be hidden.
I have been using these show/hide features since the beginning and I have only now encountered a strange phenomenon when I created a Subroutine that resets all the "Default" hidden and shown columns (there are some hidden by default).
This sub is called when the workbook is opened and also enters in some Error Handlers; it is there to make sure that anything hidden by the previous user is unhidden upon starting (or vice versa).
Suddenly, anytime I open the workbook and use the following scripts in ANY sub I get the 1004 error:
I strongly suspect [necessary] cell comments are the issue.
I use a subroutine to resize and reposition all comments. If I Call this subroutine from a button on a worksheet, suddenly ALL of the functionality works properly again. If I Call this subroutine during the workbook_open event, the error persists. If I call it during any other sub that uses the Sheet2.Cells.EntireRow.Hidden = False code, the problem persists. And here's the thing, ONLY after I call this Sub from a worksheet button is the problem fixed, but I ALSO need to call it a second time from within the subs. I need these scripts to work when the workbook opens WITHOUT user interaction.
The following sub is called on a WorkBook_Open Event:
And this is the ResetComments code:
I have spent a lot of time googling, this appears to be an oddball. If you need more code I can supply it but I cannot send the entire workbook since it contains some confidential info.
I have been using these show/hide features since the beginning and I have only now encountered a strange phenomenon when I created a Subroutine that resets all the "Default" hidden and shown columns (there are some hidden by default).
This sub is called when the workbook is opened and also enters in some Error Handlers; it is there to make sure that anything hidden by the previous user is unhidden upon starting (or vice versa).
Suddenly, anytime I open the workbook and use the following scripts in ANY sub I get the 1004 error:
Code:
Sheet2.Cells.EntireRow.Hidden = False
Sheet3.Cells.EntireRow.Hidden = False
Sheet2.Cells.EntireColumn.Hidden = False
Sheet3.Cells.EntireColumn.Hidden = False
I use a subroutine to resize and reposition all comments. If I Call this subroutine from a button on a worksheet, suddenly ALL of the functionality works properly again. If I Call this subroutine during the workbook_open event, the error persists. If I call it during any other sub that uses the Sheet2.Cells.EntireRow.Hidden = False code, the problem persists. And here's the thing, ONLY after I call this Sub from a worksheet button is the problem fixed, but I ALSO need to call it a second time from within the subs. I need these scripts to work when the workbook opens WITHOUT user interaction.
The following sub is called on a WorkBook_Open Event:
Code:
Public Sub defaultSortAndFilter()
Dim i As Long
Dim rowArrayPG
rowArrayPG = Array(15, 19, 21, 25, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51)
Dim rowArrayMD
rowArrayMD = Array(15, 18, 20, 24, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49)
Call ResetComments
Sheet2.Cells.EntireRow.Hidden = False
Sheet3.Cells.EntireRow.Hidden = False
Sheet2.Cells.EntireColumn.Hidden = False
Sheet3.Cells.EntireColumn.Hidden = False
Dim lastColPG As Long
lastColPG = Sheet2.Cells(5, Columns.Count).End(xlToLeft).Column
revertLastColPG = lastColPG
Dim lastColMD As Long
lastColMD = Sheet3.Cells(5, Columns.Count).End(xlToLeft).Column
revertLastColMD = lastColMD
Dim sortRangePG As Range
Set sortRangePG = Range(Cells(5, 3), Cells(55, lastColPG))
Dim sortRangeMD As Range
Set sortRangeMD = Range(Cells(5, 3), Cells(53, lastColMD))
Application.ScreenUpdating = False
On Error GoTo ExplodeSheets
For i = 0 To UBound(rowArrayPG)
Sheet2.Rows(rowArrayPG(i)).EntireRow.Hidden
Next
For i = 0 To UBound(rowArrayMD)
Sheet3.Rows(rowArrayMD(i)).EntireRow.Hidden
Next
Sheet2.Range("sortRangePG").Sort Key1:=Range("C5"), Order1:=xlAscending, Orientation:=xlSortRows, Key2:=Range("C6"), Order2:=xlAscending, Key3:=Range("C9"), Order3:=xlAscending
Sheet3.Range("sortRangeMD").Sort Key1:=Range("C5"), Order1:=xlAscending, Orientation:=xlSortRows, Key2:=Range("C6"), Order2:=xlAscending, Key3:=Range("C9"), Order3:=xlAscending
Application.ScreenUpdating = True
Exit Sub
ExplodeSheets:
Sheet2.Cells.EntireRow.Hidden = False
Sheet3.Cells.EntireRow.Hidden = False
Sheet2.Cells.EntireColumn.Hidden = False
Sheet3.Cells.EntireColumn.Hidden = False
Application.ScreenUpdating = True
End Sub
And this is the ResetComments code:
Code:
Sub ResetComments()
Dim cmt As Comment
For Each cmt In Sheet2.Comments
cmt.Shape.Top = cmt.Parent.Top + 5
cmt.Shape.Left = cmt.Parent.Offset(0, 1).Left + 5
cmt.Shape.Height = 0
cmt.Shape.Width = 0
Next
For Each cmt In Sheet3.Comments
cmt.Shape.Top = cmt.Parent.Top + 5
cmt.Shape.Left = cmt.Parent.Offset(0, 1).Left + 5
cmt.Shape.Height = 0
cmt.Shape.Width = 0
Next
End Sub
I have spent a lot of time googling, this appears to be an oddball. If you need more code I can supply it but I cannot send the entire workbook since it contains some confidential info.