How to use a range for target address in VBA

albert_de

New Member
Joined
Mar 16, 2020
Messages
20
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
I have a worksheet that has Dependant Dropdown Lists in it (Column J & K). Importantly, the same lists in Column J & K repeat in the rows below.

1709960412620.png


I am trying to get the Dropdown List in Column K to display "Select Name>>" whenever the Column J Dropdown List is changed.
And ideally for a cell in Column K to remain blank if the adjacent cell in Column J is blank.

I have found the following VBA instruction on how to do this, and it works perfectly for me, but of course it will only affect Row 16 and none of the rows below it (e.g. Range J16:J200 or K16:K200).

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$J$16" Then
Range("K16").Value = "Select Name>>"
End If
End Sub


How do I modify this VBA code so that the:

- Dropdown List in Column K displays "Select Name>>" whenever the Column J Dropdown List is changed
- cell in Column K remains blank if the adjacent cell in Column J is blank.

Thank you for any help that you can offer a non VBA mastermind.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.CountLarge > 1 Then Exit Sub
    If Not Intersect(Target, Range(" J16:J200")) Is Nothing Then
        
        Application.EnableEvents = False
        If Target = "" Then
            Target.Offset(0, 1) = ""
        Else
            Target.Offset(0, 1) = "Select Name>>"
        End If
        Application.EnableEvents = True
        
    End If

End Sub
 
Upvote 0
Solution
Hi Akuini

Thank you for your very prompt response to my question.
Your code works perfectly and exactly as requested in my post. You have saved me days!
Thank you :)
 
Upvote 0
Hi Akuini

Thank you for your very prompt response to my question.
Your code works perfectly and exactly as requested in my post. You have saved me days!
Thank you :)
 
Upvote 0
Hi Akuini

Thank you for your very prompt response to my question.
Your code works perfectly and exactly as requested in my post. You have saved me days!
Thank you :)
You're welcome, glad to help & thanks for the feedback.:)
Note:
The code is designed to handle changes in individual cells only, so it won't work when you copy multiple cells at once to the specified range. If that is a possible scenario, then we need to amend the code.
 
Upvote 0
Thank you again Akuini. At this stage I don't think that I will be copying multiple cells at once to the specified range. But should I find that I need to do this I will repost here.
How good is Excel!
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,970
Members
449,095
Latest member
Mr Hughes

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