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
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi I have put the above code in 'This Workbook' if this is correct, hope you can help.
 
Upvote 0
hi I have tried this code as well but still don't work. hope you can help
Code:
Private Sub Workbook_Open()
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
Your last code works ,but there is a Quotation Mark missing in the line below !!!
Code:
Set Rng = .Range(.Range("G2[COLOR="#FF0000"][B][SIZE=4]"[/SIZE][/B][/COLOR]), .Range("G" & Rows.Count).End(xlUp))
 
Upvote 0
hi thank you for that :) I have amended it now but still no list is going into the combox1 on sheet1 :(
 
Upvote 0
I should put a "Breakpoint" in the code then close and reopen to step though it, and see what's happening
 
Upvote 0
I assume as you stated previously, your code is in the "ThisWorkbook" Module !!!
In Active worksheet, Click "Alt +F11" to see code page, > click "Ctrl +R" to see Project page
Scroll down "Project Page" until you find "ThisWorkbook" > double Click to see actual related code Page.

Click somewhere at top of code , but in margin, a Brown Dot and line will appear.
Your code now has a Break Point.
When you now run the code it will stop at that line with the Code window open.
If you then start slowly clicking "F8" you will step through the code and be able to see if its working.
 
Upvote 0
Hi I have tried that each line went yellow but nothing happened on the main page
 
Upvote 0
You could try copying the code, place in basic module or button and try running it there to see that it works then try again.
You could also place a simple code as below in the "Thisworkbook" module to make sure that's working.
Code:
Private Sub Workbook_Open()
MsgBox "Hello"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,991
Members
452,541
Latest member
haasro02

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