Worksheet Change ByVal For Multiple Cells in Worksheet

teksp0rt

New Member
Joined
Feb 6, 2008
Messages
33
Hello, I am seeking assistance to combine these two event procedures into one Worksheet. It has been a long time since writing any code. The idea is that if I change Range F9 on my worksheet (variables are yes or no) and/or Range E9 on my worksheet (variables are yes or no) - a macro event will run. They are not dependent variables. I cut down the rest of the code, just to show a simple example of two Private Subs that I would like to execute as 1 Sub. Thank you.

----------

Private Sub Worksheet_Change(ByVal Target As Range)

Dim Comparison As Range

Set Comparison = Range("F9")

If Not Intersect(Target, Comparison) Is Nothing Then
Select Case Comparison
Case "Yes": PerformRentComparison
Case "No": HideRentComparison
End Select


End If

End Sub


Private Sub Worksheet_Change(ByVal Target As Range)

Dim SecondFloor As Range

Set SecondFloor = Range("F10")

If Not Intersect(Target, SecondFloor) Is Nothing Then
Select Case SecondFloor
Case "Yes": ShowUpstairsUnits
Case "No": HideUpstairsUnits
End Select
End If

End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try this:
Modify Msgbox example with your script name

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    'Modified  11/9/2022  10:39:33 PM  EST
If Target.Address = "$F$9" Or Target.Address = "$F$10" Then
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub

Select Case Target.Value
    Case "Yes"
        MsgBox "Yes"
     Case "No"
        MsgBox "No"
End Select
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,575
Messages
6,120,342
Members
448,956
Latest member
Adamsxl

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