drew.j.harrison
Board Regular
- Joined
- Jul 9, 2010
- Messages
- 65
So I developed some code that hides/unhides certain rows based on selections on a userform. I want it to run when a change is made to one of the userform fields that affects what should be visible. The code seems to work great when I execute the macro directly however when I set the userform to call the macro when a change is made to the userform I get an error on the line where it defines the row the selected part number is listed ("PartNumberRow"). The specific error is "Run-time error '1004': Application-defined or object-defined error". What the heck am I missing here. Why would it run just fine when executed directely but not when it is called by a userform change. Thanks for all the help.
Code:
Sub Hide_Show_Parts_And_Info()
'Show Only Selected Part Information and Parts
Application.ScreenUpdating = False
If User_Controls.View_Part.Value = "" Then
Application.ScreenUpdating = True
Exit Sub
Else
Dim PartNumber As String
Dim PartNumberRow As Long
PartNumber = User_Controls.View_Part.Value
Sheets("Imported Bid").Activate
PartNumberRow = Range("Test_Range").Find(What:=PartNumber).Row
Dim Range1Top, Range2Top, Range1Bottom, Range2Bottom, Range1, Range2 As Range
Set Range1Top = Cells(7, 1)
Set Range1Bottom = Cells(PartNumberRow - 1, Range1Top.Column)
Set Range2Top = Cells(PartNumberRow + 41, 1)
Set Range2Bottom = Cells(1300, Range2Top.Column)
Set Range1 = Range(Range1Top, Range1Bottom)
Set Range2 = Range(Range2Top, Range2Bottom)
If PartNumberRow = 7 Then
Range2.EntireRow.Hidden = True
Else
Range1.EntireRow.Hidden = True
Range2.EntireRow.Hidden = True
End If
End If
Application.ScreenUpdating = True
End Sub