Fault 1004 range of object aplication failed on userform.show

DB73

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

another problem to solve for me
i have a sheet with some buttons, 1 is for showing my userform (MyForm)

Code to show userform;
VBA Code:
Private Sub CommandButton1_Click()
MyForm.Show
End Sub
this 1 is on sheet18(gegevens invoer)

This 1 is on the userform;
Code to load the cmbxs;
VBA Code:
Private Sub UserForm_Initialize()

        ComboBox1.List = Application.Range("werkdag_ziek_verlof").value
        ComboBox2.List = Application.Range("projecten").value
        ComboBox3.List = Application.Range("adressen").value
        ComboBox4.List = Application.Range("normale_uren_over_uren").value
        'ComboBox5.List = Application.Range("uur_tarief_percentage").value
        'cbx5
            Dim cell As Range
             For Each cell In Application.Range("uur_tarief_percentage").Cells
                ComboBox5.AddItem cell.Text
                    Next cell
        ComboBox6.List = Application.Range("werktijden").value
        ComboBox7.List = Application.Range("werktijden").value
        ComboBox8.List = Application.Range("pauze_geen_pauze").value
        ComboBox9.List = Application.Range("BTW_verlegd").value
        'ComboBox10.List = Application.Range("BTW_heffing").value
        'cbx10
            For Each cell In Application.Range("btw_heffing").Cells
                ComboBox10.AddItem cell.Text
                    Next cell
        'ComboBox11.List = Application.Range("adressen[klantnaam]").value
        'ComboBox11
            With ComboBox11
              .ColumnCount = 5
                .List = Range("adressen").value
                  End With
        ComboBox12.List = Application.Range("adressen[klantnaam]").value
        ComboBox13.List = Application.Range("enkel_retour_rit").value
        ComboBox14.List = Application.Range("woon_werk_zakelijk").value
        ComboBox15.List = Application.Range("te_declareren_per_km").value
        ComboBox16.List = Application.Range("overige_declaratie").value
        ComboBox17.List = Application.Range("reden_rit").value
        ComboBox18.List = Application.Range("te_declareren_per_km").value
        ComboBox19.List = Application.Range("vervoer").value
        ComboBox20.List = Application.Range("reden_overige_declaratie").value
End Sub

on my search on the WWW i found that it could be a UserForm_Initialize() that causes the problem.
so i skipped items on the UserForm_Initialize() part to look which line causes the problem, but i cant figur out which one.
if i remove the whole code it seems to work and the userform pops up but, without the comboboxes population

any help on this one will be apreciate
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hard to tell, did you step through the initialize code line by line until the error occurred? or is that what you meant by "skipped items"?
 
Upvote 0
try this line : ComboBox12.List = Application.Range("adressen[klantnaam]").value
 
Upvote 0
Hard to tell most look to be named ranges. Try accessing them using this format instead:
VBA Code:
ComboBox##.RowSource = Sheets("SheetName").ListObjects("NamedRange").DataBodyRange.Address(External:=true)
 
Upvote 0
try this line : ComboBox12.List = Application.Range("adressen[klantnaam]").value
that 1 isnt right, but this 1 does the job;
VBA Code:
ComboBox12.List = Application.Range("adressen").value

but i changed it to;
VBA Code:
        With ComboBox12
              .ColumnCount = 5
                .List = Range("adressen").value
                  End With
cbx12 is the same as cbx11

i think i forgot due to many changes last update in my file...
i'm still learning:giggle:
 
Upvote 0
Hard to tell, did you step through the initialize code line by line until the error occurred? or is that what you meant by "skipped items"?
i just removed some lines an tested if it works...afte removing the whole code the userform popt up on the cmdbutton.

but the problem is solved...thanks for the help anyway....(y)
 
Upvote 0
In the VB Editor goto Tools, Options, General, & check the "Break in class module"
That way when it fails you can click the debug button & it will takes you to the problem.
 
Upvote 0
that 1 isnt right, but this 1 does the job;
VBA Code:
ComboBox12.List = Application.Range("adressen").value

but i changed it to;
VBA Code:
        With ComboBox12
              .ColumnCount = 5
                .List = Range("adressen").value
                  End With
cbx12 is the same as cbx11

i think i forgot due to many changes last update in my file...
i'm still learning:giggle:
All good! We all began learning somewhere! :giggle:
 
Upvote 0
the problem for me is that if theres a fail i only can find the yellow marked lines, for this one it gaves a yellow marker on the "userform.show"
so, i could find anything else
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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