commandbutton gives fault

DB73

Board Regular
Joined
Jun 7, 2022
Messages
102
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2010
  6. 2007
Platform
  1. Windows
  2. Mobile
  3. Web
hi guys,

i've got al little (big) problem
got 2 commandbuttons (cmdb1, cmdb2)
cmdb1 is working and opens my userform
cmdb2 (factuur) is on the same sheet but doesnt seem to work ??
i use these 2 codes to call my userforms;
VBA Code:
Private Sub CommandButton1_Click()
    MyForm.Show
End Sub

Private Sub commandbutton2_Click()
    Factuur.Show
End Sub
tried to remove the buttons and make new
checked 100 times if the name was correct.
i use office365
fault code is "Subscript Out of Range Runtime Error (Error 9)"
also noticed that as i open the userform the window is just out of my screen, i make it fit everytime but after openening the spreatsheet again, its too wide again
what could it be ?

thanks in advance
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
In which vba module is the Sub CommandButton1_Click and in which the Sub commandbutton2_Click?
Is Factuur a userform? Can you share Factuur's UserForm_Activate and UserForm_Initialize code?
If you add a Stop in the Sub commandbutton2_Click code, does the code stop on that instruction when you press Command_Button_2?
VBA Code:
Private Sub commandbutton2_Click()
    Stop                                 '<<< ADD FOR TESTING
    Factuur.Show
End Sub
(if the code stops you may restart execution by pressing F5)

Let us know...
 
Upvote 0
Hi anthony,
thamks for reply
In which vba module is the Sub CommandButton1_Click and in which the Sub commandbutton2_Click?
i didnt put it in a module, just opened a new sheet and added to buttons (activeX)
then i opened the sheet in vbe editor and put in the code.
Knipsel.JPG

Is Factuur a userform?
Yes
Can you share Factuur's UserForm_Activate and UserForm_Initialize code?
Activate ?? that what i made that button for.
Initialize:
VBA Code:
'laad de klanten in de combobox
Private Sub UserForm_Initialize()
       Me.ComboBox1.List = ActiveSheet.ListObjects("adressen").ListColumns(1).DataBodyRange.value
End Sub
'zet de adres gegevens in de textboxen
Private Sub ComboBox1_Change()
    TextBox1.Text = Application.VLookup(ComboBox1.value, Worksheets("adressen").Range("adressen"), 3, False)
    TextBox2.Text = Application.VLookup(ComboBox1.value, Worksheets("adressen").Range("adressen"), 4, False)
    TextBox3.Text = Application.VLookup(ComboBox1.value, Worksheets("adressen").Range("adressen"), 5, False)
    TextBox4.Text = Application.VLookup(ComboBox1.value, Worksheets("adressen").Range("adressen"), 6, False)
    TextBox5.Text = Application.VLookup(ComboBox1.value, Worksheets("adressen").Range("adressen"), 7, False)
    TextBox6.Text = Application.VLookup(ComboBox1.value, Worksheets("adressen").Range("adressen"), 8, False)
End Sub
If you add a Stop in the Sub commandbutton2_Click code, does the code stop on that instruction when you press Command_Button_2?
still got the same error then
 
Upvote 0
Found someting myself 😇

changed this
VBA Code:
Private Sub UserForm_Initialize()
       Me.ComboBox1.List = ActiveSheet.ListObjects("adressen").ListColumns(1).DataBodyRange.value
End Sub
into this
VBA Code:
Private Sub UserForm_Initialize()
       ComboBox1.List = Application.Range("adressen").value
End Sub

dont know why, but this works
 
Upvote 0
Found someting myself 😇

changed this
VBA Code:
[...]

into this
VBA Code:
Private Sub UserForm_Initialize()
       ComboBox1.List = Application.Range("adressen").value
End Sub

dont know why, but this works

Any failure in the UserForm_Initialize code results in the form not loaded.

Maybe "adressen" is not a ListObject (a structured Table) but simply a "named range"
But the important point is that "this works!"
 
Upvote 0
Any failure in the UserForm_Initialize code results in the form not loaded.

Maybe "adressen" is not a ListObject (a structured Table) but simply a "named range"
But the important point is that "this works!"
actualy 'adressen" is a table, thats why i found it a strange thing.

but what u said....it works..

anyway..thanks for the help😉
 
Upvote 0

Forum statistics

Threads
1,214,407
Messages
6,119,332
Members
448,888
Latest member
Arle8907

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