Streamline TargetAddress code

ChristineJ

Well-known Member
Joined
May 18, 2009
Messages
762
Office Version
  1. 365
Platform
  1. Windows
How can the code below be consolidated so that when a cell in B4:B5, B8:B18, B21:B27, B30:B32, B31:B39, B41:B43, and B46:B50 is selected, the word "No" appears in column C in the same row? Thanks!

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Address = "$B$4" Then
Range("C4").Value = "No"
End If

If Target.Address = "$B$5" Then
Range("C5").Value = "No"
End If

If Target.Address = "$B$8" Then
Range("C8").Value = "No"
End If

If Target.Address = "$B$9" Then
Range("C9").Value = "No"
End If

If Target.Address = "$B$10" Then
Range("C10").Value = "No"
End If

If Target.Address = "$B$11" Then
Range("C11").Value = "No"
End If

End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
How about
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("B4:B5, B8:B18, B21:B27, B30:B32, B31:B39, B41:B43,B46:B50")) Is Nothing Then
      Target.Offset(, 1).Value = "No"
   End If
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("B4:B5, B8:B18, B21:B27, B30:B32, B31:B39, B41:B43,B46:B50")) Is Nothing Then
      Target.Offset(, 1).Value = "No"
   End If
End Sub
Thanks! Works perfectly! CJ
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,216,123
Messages
6,128,975
Members
449,480
Latest member
yesitisasport

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