ComboBox1 in sheet1 list source in sheet2 how to do vba code

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hi please can you help I have a combobox with a dropdown in sheet1, the data I want it to list is in sheet2 G2 to last row, please can you look at my code below and advise how to correct it. thanks again

HTML:
Private Sub Workbook_Open()
With Sheet1.ComboBox1
    ComboBox1.RowSource = ("Sheet2")
    ComboBox1.List = .Range("G2:G" & .Range("G" & Rows.Count).End(xlUp).Row).Value
End Sub
 
Hi, I got it working now I changed the sub worksheet to activate :). an you advise tough how can I add anther ComboBox2 with range of A2 to last row please?
Code:
Private Sub Workbook_Activate()
Dim Rng As Range, Dn As Range
With Sheets("Sheet2")
    Set Rng = .Range(.Range("G2"), .Range("G" & Rows.Count).End(xlUp))
End With
With Sheets("Sheet1").ComboBox1
    .Clear
    .List = Rng.Value
End With

End Sub
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Something Like this:-
NB:- Make sure you have "Combobox2 in sheet1.
Code:
Private [COLOR="Navy"]Sub[/COLOR] Workbook_Open()
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Rng2 [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]With[/COLOR] Sheets("Sheet2")
    [COLOR="Navy"]Set[/COLOR] Rng = .Range(.Range("G2"), .Range("G" & Rows.Count).End(xlUp))
    [COLOR="Navy"]Set[/COLOR] Rng2 = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]With[/COLOR] Sheets("Sheet1")
    .ComboBox1.Clear
    .ComboBox1.List = Rng.Value
    .ComboBox2.Clear
    .ComboBox2.List = Rng2.Value
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
hi thanks for your help, I have entered the code below but combobox2 has no list in it but combobox1 has, combobox2 is in sheet1
Code:
Private Sub Workbook_Open()
Dim Rng As Range, Dn As Range, Rng2 As Range
With Sheets("Sheet2")
    Set Rng = .Range(.Range("G2"), .Range("G" & Rows.Count).End(xlUp))
    Set Rng2 = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
End With
With Sheets("Sheet1")
    .ComboBox1.Clear
    .ComboBox1.List = Rng.Value
    .ComboBox2.Clear
    .ComboBox2.List = Rng2.Value
End With
End Sub
 
Upvote 0
hi just realized what I did wrong it works now many thanks, I copied the last combobox instead of adding a new one :)
 
Upvote 0

Forum statistics

Threads
1,224,754
Messages
6,180,749
Members
452,996
Latest member
nelsonsix66

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