multiple cell links

Ed3m

New Member
Joined
Mar 10, 2004
Messages
35
Is this possible and if so how.I would like to link a combo box to different cells on different sheets.
 

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,014
Assuming this is for a ComboBox that is located on a Worksheet not a UserForm (though adapting it for a UserForm would not be too difficult). This works for me in testing:

<font face=Courier New>
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> ComboBox1_GotFocus()
    <SPAN style="color:#00007F">Dim</SPAN> rngCell <SPAN style="color:#00007F">As</SPAN> Range
    <SPAN style="color:#00007F">For</SPAN> i = Me.ComboBox1.ListCount - 1 <SPAN style="color:#00007F">To</SPAN> 0 <SPAN style="color:#00007F">Step</SPAN> -1
        Me.ComboBox1.RemoveItem i
    <SPAN style="color:#00007F">Next</SPAN> i
        
    <SPAN style="color:#007F00">' [RangeOne] = Cells A1:A5 on Sheet4</SPAN>
    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> rngCell <SPAN style="color:#00007F">In</SPAN> [RangeOne].Cells
        Me.ComboBox1.AddItem rngCell.Value
    <SPAN style="color:#00007F">Next</SPAN> rngCell
    
    <SPAN style="color:#007F00">' [RangeTwo] = Cells F5:F8 on Sheet1</SPAN>
    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> rngCell <SPAN style="color:#00007F">In</SPAN> [RangeTwo].Cells
        Me.ComboBox1.AddItem rngCell.Value
    <SPAN style="color:#00007F">Next</SPAN> rngCell

<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

</FONT>

HTH
 

viper

Active Member
Joined
Feb 15, 2002
Messages
382
Just use:

Combobox1.additem Sheet2.cells(1,1). Value
Combobox1.additem sheet3.cells(5,7).Value
Combobox1.additem Sheet8.cells(20,8).Value

HTH
 

Ed3m

New Member
Joined
Mar 10, 2004
Messages
35
i tried vipers suggestion however all i get is runtime error 424 :confused:
 

viper

Active Member
Joined
Feb 15, 2002
Messages
382
Sorry didn't specify where to put the code.

Put the code into your workbook_open event so the code will look like this:

'change the sheet1 to your sheet name that contains the combobox
'change the combobox1 to your combobox name if different
'change Sheet2 & 3 name to yours
'for reference Cells(7, 5) is equal to Cell E7 on Sheet2

Code:
Private Sub Workbook_Open()
    Sheet1.ComboBox1.AddItem Sheet2.Cells(7, 5).Value
    Sheet1.ComboBox1.AddItem Sheet3.Cells(6, 5).Value
    
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,499
Messages
5,596,515
Members
414,074
Latest member
Matthew Kakde

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