question about multipage & initialize userform

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,083
Office Version
  1. 2010
hello i work a program and if i insert userform contain more than multipage on one userform but i face a problem about run code what existed in initialize userform so i have about four multipages contain one combobox for every multipage it show the item only in first multipage but not show for the rests multipage i no know if there is possible do that for all multipage or i have to insert many userform to work it

this is my code in initialize
VBA Code:
Private Sub UserForm_Initialize()
ComboBox1.RowSource = "CODES!" & Sheets("CODES").Range("A5", Sheets("CODES").Range("A65536").End(xlUp)).Address
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,709
Office Version
  1. 2013
Platform
  1. Windows
Here is a example of One Mutipage on a Userform with 2 Multipage pages
A multipage can have several Multipage pages Like a workbook have several Worksheets

The Comboboxes are name differently and get their values from different sheets and different Ranges.

Do not use RowSource
VBA Code:
Private Sub UserForm_Initialize()
'Modified  12/11/2020  3:55:35 PM  EST
Dim Lastrowa As Long
Dim Lastrowb As Long
Lastrowa = Sheets("Alpha").Cells(Rows.Count, "A").End(xlUp).Row
Lastrowb = Sheets("Bravo").Cells(Rows.Count, "B").End(xlUp).Row

MultiPage1.Page1.ComboBox1.List = Sheets("Alpha").Range("A1:A" & Lastrowa).Value
MultiPage1.Page2.ComboBox2.List = Sheets("Bravo").Range("B1:B" & Lastrowb).Value

End Sub
 

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,083
Office Version
  1. 2010
thanks for your replying actually i was wrong about number the combo box it should 2 in page 2 and 3 in page3 I tested your code and I amended a little but it gives me error

Object Doesn’t Support This Property or Method​

the row source should be one column a and the same sheet
VBA Code:
Private Sub UserForm_Initialize()
Dim Lastrowa As Long
Lastrowa = Sheets("codes").Cells(Rows.Count, "A").End(xlUp).Row
MultiPage1.Page1.ComboBox1.List = Sheets("codes").Range("A1:A" & Lastrowa).Value
MultiPage1.Page2.ComboBox2.List = Sheets("codes").Range("A1:A" & Lastrowa).Value
End Sub
and another question I have each page on userform about 10 combobox how can I do the code by array you know to write about 10 lines into code it takes more time
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,709
Office Version
  1. 2013
Platform
  1. Windows
thanks for your replying actually i was wrong about number the combo box it should 2 in page 2 and 3 in page3 I tested your code and I amended a little but it gives me error

Object Doesn’t Support This Property or Method​

the row source should be one column a and the same sheet
VBA Code:
Private Sub UserForm_Initialize()
Dim Lastrowa As Long
Lastrowa = Sheets("codes").Cells(Rows.Count, "A").End(xlUp).Row
MultiPage1.Page1.ComboBox1.List = Sheets("codes").Range("A1:A" & Lastrowa).Value
MultiPage1.Page2.ComboBox2.List = Sheets("codes").Range("A1:A" & Lastrowa).Value
End Sub
and another question I have each page on userform about 10 combobox how can I do the code by array you know to write about 10 lines into code it takes more time
When I run your code it works for me. Are you sure you have a sheet named "codes"

And you said:
and another question I have each page on userform about 10 combobox how can I do the code by array you know to write about 10 lines into code it takes more time

I think first we should get what you have working first.

So are you loading all the comboboxes on all of the pages with data from the same sheet and same range. Which appears to always be column A
 

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,083
Office Version
  1. 2010

ADVERTISEMENT

When I run your code it works for me. Are you sure you have a sheet named "codes"
yes I'm sure about sheet named "codes" and i tested again it gives me error
I think first we should get what you have working first.
I have on userform page3 = cmobobox from 2 to 30 and page 4 = combobox from 31 to 45
So are you loading all the comboboxes on all of the pages with data from the same sheet and same range. Which appears to always be column A
yes you're right
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,709
Office Version
  1. 2013
Platform
  1. Windows
You need some code like this:
It refers to The Multipage and the Page on the userform and the Combobox

VBA Code:
Private Sub CommandButton2_Click()
'Modified  12/12/2020  12:01:47 PM  EST
Cells(1, 2).Value = MultiPage1.Page1.ComboBox1.Value
Cells(1, 3).Value = MultiPage1.Page2.ComboBox2.Value

End Sub
 

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,083
Office Version
  1. 2010

ADVERTISEMENT

what about have many combobox each page?
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,709
Office Version
  1. 2013
Platform
  1. Windows
This script will load all the Comboboxes in your Userform with the values in Column A of sheet named "Codes"
VBA Code:
Private Sub CommandButton2_Click()
'Modified  12/12/2020  1:40:34 PM  EST
Dim Lastrow As Long
Lastrow = Sheets("Codes").Cells(Rows.Count, "A").End(xlUp).Row
Dim ctrl As MSForms.Control
 For Each ctrl In Me.Controls
    Select Case True
        Case TypeOf ctrl Is MSForms.ComboBox
            ctrl.List = Sheets("Codes").Range("A1:A" & Lastrow).Value
    End Select
Next ctrl
End Sub
 

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,083
Office Version
  1. 2010
sorry what I say you but I have to make also based on column b ,c the same sheet("code")
the combobox from 1 to 10 based on column a and from 11 to 20 based on column b and from 21 to 30 based on column c
sorry again I don't mentioned from the beginning
 

Forum statistics

Threads
1,141,869
Messages
5,709,092
Members
421,615
Latest member
RAB29

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
Top