question about multipage & initialize userform

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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
 
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
But earlier I asked this and you said this:
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
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
from the beginning is right but recently I've found it I have three columns not column1 , forgive me i don't focus very well ,this is my mistake and I'm sorry if I waste your time
 
Upvote 0
Try this:
VBA Code:
Private Sub CommandButton2_Click()
'Modified  12/12/2020  2:48:23 PM  EST
Dim i As Long
i = 0
Dim Lastrow As Long

Dim ctrl As MSForms.Control
 For Each ctrl In Me.Controls

    Select Case True
        Case TypeOf ctrl Is MSForms.ComboBox
            ctrl.Clear
                i = i + 1
            Select Case i
        
        Case 1 To 10
            Lastrow = Sheets("Codes").Cells(Rows.Count, "A").End(xlUp).Row
            ctrl.List = Sheets("Codes").Range("A1:A" & Lastrow).Value
        Case 11 To 20
            Lastrow = Sheets("Codes").Cells(Rows.Count, "B").End(xlUp).Row
            ctrl.List = Sheets("Codes").Range("B1:B" & Lastrow).Value
        Case 21 To 30
            Lastrow = Sheets("Codes").Cells(Rows.Count, "C").End(xlUp).Row
            ctrl.List = Sheets("Codes").Range("C1:C" & Lastrow).Value
    End Select
    End Select
Next ctrl

End Sub
 
Upvote 0
Solution
perfect I would ask you about another page begins from 32 to 60 I do the same thing as the code
 
Upvote 0
perfect I would ask you about another page begins from 32 to 60 I do the same thing as the code
So I believe your saying the code works but now you have 32 to 60
And you see how to do that yourself is what i think you mean.

If you can do it yourself you see how the code is working and you know how to do it now yourself
That's great. If you need more help let me know.

I'm still not sure what the overall object is but I presume you believe this is the best way to do what you want.
Having 60 comboboxes on one userform is a lot.

Glad to see you know how to use Mutipages on a Userform

Some users here think you need 10 or more Userforms

A Multipage is like having pages in a book
Or sheets in a Workbook.
Glad to see your learning Excel and understanding how it works
Again if you need more help let me know.

If you have some Comboboxes you want to skip over you could ask and I can give you a answer on how to skip over those.
You would have to give those Comboboxes names like "Alpha" and "Bravo" or such
And we tell the script to skip over those Comboboxes Named "Alpha" and "Bravo"


Mary being the name
 
Upvote 0
this is the final code
VBA Code:
Private Sub UserForm_Initialize()
Dim i As Long
i = 0
Dim Lastrow As Long
Dim ctrl As MSForms.Control
For Each ctrl In Me.Controls
    Select Case True
        Case TypeOf ctrl Is MSForms.ComboBox
            ctrl.Clear
                i = i + 1
            Select Case i
       
        Case 1 To 10
            Lastrow = Sheets("Codes").Cells(Rows.Count, "A").End(xlUp).Row
            ctrl.List = Sheets("Codes").Range("A1:A" & Lastrow).Value
        Case 11 To 20
            Lastrow = Sheets("Codes").Cells(Rows.Count, "B").End(xlUp).Row
            ctrl.List = Sheets("Codes").Range("B1:B" & Lastrow).Value
        Case 21 To 30
            Lastrow = Sheets("Codes").Cells(Rows.Count, "C").End(xlUp).Row
            ctrl.List = Sheets("Codes").Range("C1:C" & Lastrow).Value
            Case 31 To 40
            Lastrow = Sheets("Codes").Cells(Rows.Count, "A").End(xlUp).Row
            ctrl.List = Sheets("Codes").Range("A1:A" & Lastrow).Value
            Case 41 To 50
            Lastrow = Sheets("Codes").Cells(Rows.Count, "b").End(xlUp).Row
            ctrl.List = Sheets("Codes").Range("b1:b" & Lastrow).Value
            Case 51 To 60
            Lastrow = Sheets("Codes").Cells(Rows.Count, "c").End(xlUp).Row
            ctrl.List = Sheets("Codes").Range("c1:c" & Lastrow).Value
           
    End Select
    End Select
Next ctrl

End Sub
your code is perfect many thanks and i hope accept my apology if my question is not clear from the beginning
 
Upvote 0
this is the final code
VBA Code:
Private Sub UserForm_Initialize()
Dim i As Long
i = 0
Dim Lastrow As Long
Dim ctrl As MSForms.Control
For Each ctrl In Me.Controls
    Select Case True
        Case TypeOf ctrl Is MSForms.ComboBox
            ctrl.Clear
                i = i + 1
            Select Case i
      
        Case 1 To 10
            Lastrow = Sheets("Codes").Cells(Rows.Count, "A").End(xlUp).Row
            ctrl.List = Sheets("Codes").Range("A1:A" & Lastrow).Value
        Case 11 To 20
            Lastrow = Sheets("Codes").Cells(Rows.Count, "B").End(xlUp).Row
            ctrl.List = Sheets("Codes").Range("B1:B" & Lastrow).Value
        Case 21 To 30
            Lastrow = Sheets("Codes").Cells(Rows.Count, "C").End(xlUp).Row
            ctrl.List = Sheets("Codes").Range("C1:C" & Lastrow).Value
            Case 31 To 40
            Lastrow = Sheets("Codes").Cells(Rows.Count, "A").End(xlUp).Row
            ctrl.List = Sheets("Codes").Range("A1:A" & Lastrow).Value
            Case 41 To 50
            Lastrow = Sheets("Codes").Cells(Rows.Count, "b").End(xlUp).Row
            ctrl.List = Sheets("Codes").Range("b1:b" & Lastrow).Value
            Case 51 To 60
            Lastrow = Sheets("Codes").Cells(Rows.Count, "c").End(xlUp).Row
            ctrl.List = Sheets("Codes").Range("c1:c" & Lastrow).Value
          
    End Select
    End Select
Next ctrl

End Sub
your code is perfect many thanks and i hope accept my apology if my question is not clear from the beginning
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
 
Upvote 0

Forum statistics

Threads
1,214,403
Messages
6,119,309
Members
448,886
Latest member
GBCTeacher

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