Getting runtime error when sub executed through userform change rather than directly

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
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You're missing a few of Find's arguments. Maybe they are set wrongly. What's saved between calls is list in VBA Help.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top