*** Worksheet_Change Error - Combining code in the same worksheet ! ***

Zwen

New Member
Joined
Jul 22, 2011
Messages
8
Hi, Am trying to combine two Worksheet_Change commands in the same worksheet but keep getting a Worksheet_Change error message. The codes are below and they are each running off a separate combo boxes located on the same work sheet performing separate functions on two alternative worksheets. I'm aware that they can be combined but so far have not been able to figure out how to do this correctly. Any help would be appreciated. Tx

1#

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$I$24" Then
Sheets("Inputs").Scenarios(Target.Value).Show

End If

End Sub



2#

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$I$29" Then
Sheets("DCF_Analysis").Scenarios(Target.Value).Show

End If

End Sub
 
The syntax I posted is correct so I suspect the error lies in whatever these lines are meant to do:

Sheets("Inputs").Scenarios(Target.Value).Show

and

Sheets("DCF_Analysis").Scenarios(Target.Value).Show



I cannot tell much beyond that because I can't see your workbook, but maybe the sheet names are wrong or the scenario is wrong or the target value is misleading to VBA when you think it means one thing and VBA thinks it means another. Some component of those objects in the code lines are not correct, or not being represented to VBA correctly.
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
SHG - fiddled around with the syntax a bit and the original code that you gave me eventually worked. Many thanks.

Tom - Many thanks for the assistance. Rechecked the syntax and after rejigging I eventually got to where I needed to be. Thanks once again.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

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