I'm having an issue with deleting a row at the end of a User Form code. This is part of a much larger workbook that serves to track water and wastewater assets for DPW staff. It has multiple worksheets that serve different functions, but the overall goal is to alert the DPW staff when maintenance is due and allow them to update asset conditions when work is done on them so that they can better predict and plan for when assets need to be replaced. Among other worksheets, the workbook contains a master list of all of the assets to track when maintenance is due for each asset and individual worksheets for the various types of assets (for example, one sheet just has data about water mains on it, another has just valves, another just hydrants, etc.).
This particular part of the workbook is intended to allow the user to remove an asset from the master list of all assets in the event that it is decommissioned or demolished. That part of the code works perfectly. However, in addition to removing the asset from the overall master list, the user can select from 4 options on the User Form of what to do with the remainder of the asset data on its individual asset class worksheet. The user can select to either:
I've searched and can't find any posts about similar issues. I've tried debugging in about every way I could think of (including adding the wsAsset.Activate statement to get rid of a 1004 error, un-hiding all columns before the row is deleted, commenting out everything below the EntireRow.Delete command except Unload Me, putting the Unload Me command right after the EntireRow.Delete command, changing from the "Range" method of selecting the row to delete to the "Row" method of selection, etc.). Everything I've tried still has the subroutine exiting right after processing the EntireRow.Delete command with the User Form still showing, and I'm out of ideas. Help!?!?!?
Thanks!
Jeff
This particular part of the workbook is intended to allow the user to remove an asset from the master list of all assets in the event that it is decommissioned or demolished. That part of the code works perfectly. However, in addition to removing the asset from the overall master list, the user can select from 4 options on the User Form of what to do with the remainder of the asset data on its individual asset class worksheet. The user can select to either:
- Do no action (leave the asset alone on it's individual asset worksheet).
- Mark the asset as being decommissioned (or demolished) by changing the text format to strikethrough (which, by conditional formatting, will highlight that asset's row in red).
- Mark the asset as being demolished (or decommissioned) by hiding the asset's row.
- Remove the demolished (or decommissioned) asset from the individual asset worksheet by deleting it's entire row (and then inserting a new row below the existing list of assets, copying and pasting formulas and conditional formatting to allow new assets to be added by the user in the future).
VBA Code:
UpdateAssetClassWS:
'Updating the selected asset's individual asset class worksheet in the manner chosen by the
'OptionButton selected on the UserForm.
With wsAsset
.Activate
.Unprotect
End With
If Me.OptionButton_NoAction.Value = True Then
'No action is necessary on the individual asset class worksheet
wsAsset.Protect
ElseIf Me.OptionButton_Highlight.Value = True Then
With wsAsset.Range("A" & wsVBA.Range("Row_Asset").Value & ":" & LastColUsed & wsVBA _
.Range("Row_Asset").Value)
.Font.Strikethrough = True
.FormatConditions(1).StopIfTrue = False
.FormatConditions(1).StopIfTrue = True
End With
wsAsset.Protect
ElseIf Me.OptionButton_Hide.Value = True Then
wsAsset.Range("A" & wsVBA.Range("Row_Asset").Value).EntireRow.Hidden = True
wsAsset.Protect
ElseIf Me.OptionButton_Delete.Value = True Then
wsAsset.Range("A" & wsVBA.Range("Row_Asset").Value).EntireRow.Delete
wsAsset.Range("A" & "LastAssetType" + 1).EntireRow.Insert
wsAsset.Range("A" & "LastAssetType" + 2).EntireRow.Copy
wsAsset.Range("A" & "LastAssetType" + 1).EntireRow.PasteSpecial xlPasteAll
wsAsset.Protect
Else
MsgBox "There is an unanticipated error in the VBA code for the Remove Asset function " _
& "as the User should not have been able to click the 'Submit - Update O&M Master " _
& "List' button without first selecting one of the option buttons." & vbCrLf _
& vbCrLf _
& "Please note the wording of this error, close the workbook without saving, " _
& "and contact Jeff Edwards for debugging. He can be reached at ###-###-#### or " _
& "xxxxxxxxx@xxxxxxxxxxxx.com.", vbOKOnly + vbCritical, "Unanticipated Error"
Unload Me
Exit Sub
End If
'Preparing to exit the subroutine by closing the user form, which will trigger the
'UserForm_QueryClose subroutine to reset all of the pertinent variables on the VBA Factors
'worksheet to prepare for the next use of the Remove Asset function.
Unload Me
I've searched and can't find any posts about similar issues. I've tried debugging in about every way I could think of (including adding the wsAsset.Activate statement to get rid of a 1004 error, un-hiding all columns before the row is deleted, commenting out everything below the EntireRow.Delete command except Unload Me, putting the Unload Me command right after the EntireRow.Delete command, changing from the "Range" method of selecting the row to delete to the "Row" method of selection, etc.). Everything I've tried still has the subroutine exiting right after processing the EntireRow.Delete command with the User Form still showing, and I'm out of ideas. Help!?!?!?
Thanks!
Jeff