Sheet, range in vba

tlindeman

Active Member
Joined
Jun 29, 2005
Messages
313
I know the following is not the right code, however could someone help me point an array to a spreadsheet called "MAIN", cell A1.

Private Sub ComboBox1_GotFocus()
ComboBox1.List = Array(Range(sheet("MAIN)("a1").Value)

End Sub

Thank You
Tony
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
How can you have an array from one cell?

Do you have a bunch of values in there that you want to use to populate the combo box?
 
Upvote 0
I do have a range of values, I know how to create that, however, I need to point to a range of cells, because the values may change in the future and I have to build multiple combo boxes.

Thank you
Tony
 
Upvote 0
See if this does it for you:

<font face=Calibri><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> ComboBox1_GotFocus()<br>    <SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>        <SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> 5<br>            Me.ComboBox1.AddItem Sheets("MAIN").Range("A" & i).Value<br>        <SPAN style="color:#00007F">Next</SPAN> i<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

HTH,
 
Upvote 0
One way

Code:
Private Sub ComboBox1_GotFocus()
Dim X As Variant
X = Sheets("MAIN").Range("A1:A5")
ComboBox1.List = X
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,553
Members
452,928
Latest member
101blockchains

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