Aargh! VBA won't load a form - no apparent reason!!!

cdhoughton

Board Regular
Joined
Dec 5, 2003
Messages
170
For some inexplicable reason I have a form-loading problem.

I have a button on a main menu that is intending to unload the main menu and open this form - it works for all my other buttons, but won't work here!!!!!

My code is:
---------------
Private Sub CommandButton12_Click()
Unload Me
frmPrintYrSetting.Show

End Sub
-------------------


It gives a '91' run time error: Object Variable or With block Variable not set, and highlights the frmPrintYrSetting.Show line as being the problem.

I can't see why, can anyone offer help?!?!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Take a close look at the Initialization procedure of the frmPrintYrSetting, or the RowSource properties of ListBox or ComboBox controls in that userform. It might be that something about how they are instructed to load programmatically is not possible (such as a sheet or range name that doesn't exist), causing the error.
 
Upvote 0
Is there something wrong with this?

The sheets, ranges and combobox are all correctly named, but have I put some invalid code in?

I'm trying to set some items for my combo box for a certain range, and to include them in the combo box if they <> 0.

If this is incorrect, could you provide an alternative suggestion?

Cheers for any help offered!

-----------------------------------------
Private Sub UserForm_Initialize()
Dim z As Integer
Dim Rng As Range

z = 0
Rng = Sheets("INPUT").Range("E84")

For z = 0 To 9
If Rng.Offset(z, 0).Value <> 0 Then
ComboBox1.AddItem (Rng.Offset(z, 0).Value)
End If
Next z
End Sub
------------------------------------------------
 
Upvote 0
I don't know if this will solve your problem, but I believe when you are setting a range variable, you need to use the word "Set", i.e. I believe:

Rng = Sheets("INPUT").Range("E84")

should be

Set Rng = Sheets("INPUT").Range("E84")
 
Upvote 0
This line:
Rng = Sheets("INPUT").Range("E84")
needs to be preceded by Set:
Set Rng = Sheets("INPUT").Range("E84")
 
Upvote 0

Forum statistics

Threads
1,203,467
Messages
6,055,589
Members
444,800
Latest member
KarenTheManager

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