I have a "reset" button for users on a spreadsheet that allows them to put the data validation, formulas, formatting, and conditional formatting back in the user entry section once they've overwritten it or deleted it. I have a hidden row that contains the unaltered correct formatting and such. I want to delete the conditional formatting from the user entry area and then copy the formatting from my "reference" row and paste it over the entire user entry area.
The issue I have is that there are a few columns hidden after the user entry area that use array formulas. When I try to just copy the formatting for the whole row and paste it, I get the "cannot change part of an array" error. I think I can avoid this by only copying and pasting the formatting up to my first hidden column, but I need to do this for a lot of sheets and we will be potentially adding columns and sheets in the future.
What I'm trying to figure out is how to modify this code to locate the end of the user data (I can do whatever is needed to designate the last column to copy - I just need to know what to do) and only copy and paste to there.
Private Sub CommandButton21_Click()
ResetUnusedRows 'this is another sub I created to reset the rows the user may have deleted or altered
Dim ws As Worksheet
Set ws = ActiveSheet
With ws
.Range("A13", "AB1012").FormatConditions.Delete
.Range("6:6").Copy
.Range("A13", "AB1012").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End With
End Sub
For reference, if needed, here's the ResetUnusedRows code:
Sub ResetUnusedRows()
'Copy the reference row for the active worksheet to any unused row up to row 1012
' - for use after save - which deletes all unused rows - to add additional rows of data
Dim ws As Worksheet
Dim LastRow As Long
Dim LastUsedCell As Long
On Error GoTo ErrorHandler
Set ws = ActiveSheet
With ws
.Unprotect ""
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
LastUsedCell = .Range("A1").Offset(LastRow, 0).Row
If ws.Name = "Location" Then
.Range("6:6").Copy Range("A" & LastUsedCell, "412:412")
.Range("A" & LastUsedCell, "412:412").EntireRow.Hidden = False
ElseIf ws.Name = "VoIP" Then 'For some reason I get an error indicating the selection is too large when I go to the full 1012 on the VoIP tab
.Range("6:6").Copy Range("A" & LastUsedCell, "922:922")
.Range("A" & LastUsedCell, "922:922").EntireRow.Hidden = False
Else
.Range("6:6").Copy Range("A" & LastUsedCell, "1012:1012")
.Range("A" & LastUsedCell, "1012:1012").EntireRow.Hidden = False
End If
.Protect ""
End With
Exit Sub
ErrorHandler:
MsgBox "Description : " & Err.Description & vbNewLine & _
"Error Number : " & Err.Number & vbNewLine & _
"Error at Line: " & Erl
Resume Next
End Sub
I hope I haven't over-explained and kept anyone from potentially responding! Let me know if I can provide any additional useful details...
Thanks for any help you can provide o great forum of Excel brilliance!
Bookmarks