question about multipage & initialize userform

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,081
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
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,676
Office Version
  1. 2013
Platform
  1. Windows
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
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,081
Office Version
  1. 2010
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
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,676
Office Version
  1. 2013
Platform
  1. Windows
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
I will try again.
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,676
Office Version
  1. 2013
Platform
  1. Windows
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
 
Solution

abdelfattah

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

ADVERTISEMENT

perfect I would ask you about another page begins from 32 to 60 I do the same thing as the code
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,676
Office Version
  1. 2013
Platform
  1. Windows
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
 

abdelfattah

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

ADVERTISEMENT

ok I will try and inform you what happens
 

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,081
Office Version
  1. 2010
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
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,676
Office Version
  1. 2013
Platform
  1. Windows
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.
 

Forum statistics

Threads
1,141,614
Messages
5,707,410
Members
421,508
Latest member
Jalayne

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