Refer to a combobox in another sheet

MrThor

New Member
Joined
Aug 13, 2018
Messages
36
Hi, I want to refer to a combobox on another sheet. I want to be able to click the cell F5 in and things will happen depending to the combobox value. Is there a way to write this code on another sheet and still get it to work?

Heres my code, it works when I am on the same sheet. The code shall be at sheet2 and now it is in sheet1 (Dagbok). Can it be removed to sheet2?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim sh2 As Worksheet
Set sh2 = Worksheets("Blad2")
Dim sh1 As Worksheet
Set sh1 = Worksheets("Dagbok")




If Not Application.Intersect(Target, sh1.Range("F5")) Is Nothing And Me.ComboBox1.Value = "Jan" Then
Jan5.Show


sh1.Range("A13:A21").Value = sh2.Range("B34:B43").Value
sh1.Range("B13:B21").Value = sh2.Range("C34:C43").Value
sh1.Range("D13:D21").Value = sh2.Range("E34:E43").Value
End If




End Sub
 
Then you can use Worksheets("Dagbok").Combobox1
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try this:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Modified  8/16/2018  10:50:33 AM  EDT
Dim sh2 As Worksheet
Set sh2 = Worksheets("Blad2")
Dim sh1 As Worksheet
Set sh1 = Worksheets("Dagbok")
If Not Application.Intersect(Target, sh2.Range("F5")) Is Nothing And Sheets("Dagbok").ComboBox1.Value = "Jan" Then
Jan5.Show
sh1.Range("A13:A21").Value = sh2.Range("B34:B43").Value
sh1.Range("B13:B21").Value = sh2.Range("C34:C43").Value
sh1.Range("D13:D21").Value = sh2.Range("E34:E43").Value
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,830
Messages
6,181,225
Members
453,025
Latest member
Hannah_Pham93

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