object variable or with block variable not set

switters_aka

Board Regular
Joined
Oct 26, 2010
Messages
118
would really like some help with this if anyone has the time. I am calling userform1 with a command button on a worksheet. The form was doing exactly what I wanted it to do yesterday although I am not confident how I got there. Today however, someone else tried to run the workbook on another PC and got the object or block variable not set error. I am now getting the same error and I have no idea how to fix this. Probably something basic but as a newbie to VBA I can't see it. Any help would be greatly appreciated. Thanks in advance.


'command button code ---->
Private Sub cmdLB1_Click()
Dim userform1 As Object

userform1.Show vbModeless
End Sub

'userform code----->
Private Sub UserForm_Initialize()
'Macro Purpose: To populate a multi-column listbox with data from
' a worksheet range

Dim lbtarget As ListBox
Dim rngSource As Range
Dim subrng As Range
Dim rownum As Integer
'Set subrng = Worksheets("Criterias).Range("qual_val")

rownum = ActiveCell.Row



If rownum = 3 Then
Worksheets("Criterias").Range("selfrel_val").Name = "MyRange"

ElseIf rownum = 4 Then
Worksheets("Criterias").Range("excon_val").Name = "MyRange"


ElseIf rownum = 5 Then
Worksheets("Criterias").Range("Qual_val").Name = "MyRange"

ElseIf rownum = 6 Then
Worksheets("Criterias").Range("coord_val").Name = "MyRange"



ElseIf rownum = 7 Then
Worksheets("Criterias").Range("stratskills_val").Name = "MyRange"


ElseIf rownum = 8 Then
Worksheets("Criterias").Range("conskills_val").Name = "MyRange"


ElseIf rownum = 9 Then
Worksheets("Criterias").Range("techskills_val").Name = "MyRange"


ElseIf rownum = 10 Then
Worksheets("Criterias").Range("lmr_val").Name = "MyRange"


ElseIf rownum = 11 Then
Worksheets("Criterias").Range("rfrep_val").Name = "MyRange"


ElseIf rownum = 12 Then
Worksheets("Criterias").Range("pi_prog_val").Name = "MyRange"


ElseIf rownum = 13 Then
Worksheets("Criterias").Range("pi_org_val").Name = "MyRange"


ElseIf rownum = 14 Then
Worksheets("Criterias").Range("pi_shs_val").Name = "MyRange"


ElseIf rownum = 15 Then
Worksheets("Criterias").Range("wk_con_val").Name = "MyRange"


ElseIf rownum = 16 Then
Worksheets("Criterias").Range("wk_hrs_val").Name = "MyRange"


ElseIf rownum = 17 Then
Worksheets("Criterias").Range("phys_bur_val").Name = "MyRange"


End If

'MsgBox rownum


'Set reference to the range of data to be filled
Set rngSource = Worksheets("Criterias").Range("MyRange")

'Fill the listbox
Set lbtarget = Me.ListBox1
With lbtarget
'Determine number of columns
.ColumnCount = 2
'Set column widths
.ColumnWidths = "50;100"
'Insert the range of data supplied
.List = rngSource.Cells.Value
End With

End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
That error means that an object you've noted is not being found when it is invoked. When you DEBUG the error, which line of code is highlighted? That should narrow it down for you.

Common errors are mistyped userform object names, mistyped sheet names, mistyped named range names, or named ranges no longer actually exist due to accidental deletion.
 
Upvote 0
userform1.show vbmodeless is highlighted. I have checked numerous threads and couldn't find one where the userform name is defined as a variable in the button script which is where the show is located.
 
Upvote 0
If you have a userform named userform1, then remove the Dim userform1 As Object line.
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,700
Members
452,938
Latest member
babeneker

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