Error Setting A Worksheet Object (in Userform Initialization)

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am embarrassed to post this as this is such a basic concept ...

VBA Code:
Private Sub UserForm_Initialize()
    Dim frm_service As Object
    Dim ws_master As Worksheet
    Dim ws_thold As Worksheet
   
    mbevents = False
    Set frm_service = frm_tservices
    Set ws_master = Workbooks("task allocation.xlsm").Worksheets("Master")
    Set ws_thold = Workbooks("task allocation.xlsm").Worksheets("thold")
   
    With frm_services
        Me.Width = 366
        Me.Height = 288
        Stop
        Me.tb_permit = ws_master.Cells(srow, 3).Value
        Me.tb_event = ws_master.Cells(srow, 5).Value
       Stop
        With Worksheets("thold") 'ws_thold
            .Cells(1, 26) = "=VLOOKUP(""" & pnum & """,('D:\WSOP 2020\[permit_data.xlsx]Permit_Data'!$A3:$E2000),5,FALSE)"
        End With
        Me.tb_function = ws_thold.Cells(1, 26).Value
    End With
    mbevents = True
End Sub

Although I have set my worksheet objects, they aren't being recognized at the end of my code. [Application-defined or object-defined error]. Perhaps I can't do this in userform code?
 
Last edited by a moderator:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Disregard. it was variable srow causing the problem!
 
Last edited by a moderator:
Upvote 0
Solution

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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