VBA Worksheet_Change Help!

BenGee

Board Regular
Joined
Mar 5, 2016
Messages
196
Hi - I've been playing around for over an hour and keep getting different errors!

How can I get this code to exit sub if Target.Address = "D3" Is Blank?

My Code;
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$D$3" Is Nothing Then
        Exit Sub
    Else
        Range("$D$4").FormulaArray = "=INDEX(Roles!$B$2:$AH$12,MATCH('Maps'!B4,Roles!$A$2:$A$12,0),MATCH('Maps'!D3,Roles!$B$1:$AH$1,0))"
        Range("$D$5").FormulaArray = "=INDEX(Roles!$B$2:$AH$12,MATCH('Maps'!B5,Roles!$A$2:$A$12,0),MATCH('Maps'!D3,Roles!$B$1:$AH$1,0))"
        Range("$D$6").FormulaArray = "=INDEX(Roles!$B$2:$AH$12,MATCH('Maps'!B6,Roles!$A$2:$A$12,0),MATCH('Maps'!D3,Roles!$B$1:$AH$1,0))"
        Range("$D$7").FormulaArray = "=INDEX(Roles!$B$2:$AH$12,MATCH('Maps'!B7,Roles!$A$2:$A$12,0),MATCH('Maps'!D3,Roles!$B$1:$AH$1,0))"
        Range("$D$8").FormulaArray = "=INDEX(Roles!$B$2:$AH$12,MATCH('Maps'!B8,Roles!$A$2:$A$12,0),MATCH('Maps'!D3,Roles!$B$1:$AH$1,0))"
        Range("$D$9").FormulaArray = "=INDEX(Roles!$B$2:$AH$12,MATCH('Maps'!B9,Roles!$A$2:$A$12,0),MATCH('Maps'!D3,Roles!$B$1:$AH$1,0))"
        Range("$D$10").FormulaArray = "=INDEX(Roles!$B$2:$AH$12,MATCH('Maps'!B10,Roles!$A$2:$A$12,0),MATCH('Maps'!D3,Roles!$B$1:$AH$1,0))"
        Range("$D$11").FormulaArray = "=INDEX(Roles!$B$2:$AH$12,MATCH('Maps'!B11,Roles!$A$2:$A$12,0),MATCH('Maps'!D3,Roles!$B$1:$AH$1,0))"
        Range("$D$12").FormulaArray = "=INDEX(Roles!$B$2:$AH$12,MATCH('Maps'!B12,Roles!$A$2:$A$12,0),MATCH('Maps'!D3,Roles!$B$1:$AH$1,0))"
        Range("$D$13").FormulaArray = "=INDEX(Roles!$B$2:$AH$12,MATCH('Maps'!B13,Roles!$A$2:$A$12,0),MATCH('Maps'!D3,Roles!$B$1:$AH$1,0))"
        Range("$D$14").FormulaArray = "=INDEX(Roles!$B$2:$AH$12,MATCH('Maps'!B14,Roles!$A$2:$A$12,0),MATCH('Maps'!D3,Roles!$B$1:$AH$1,0))"
    End If
End Sub

Thank you!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
try
Code:
If Target.Value= "" Then
or maybe
Code:
If Target.Value= ""  and target.address <> "$D$3" Then
 
Last edited:
Upvote 0
Do you mean exit the sub if Target isn't the cell D3 or exit the sub if Target is the cell D3 but D3 is empty?
 
Upvote 0
Thanks for your responses so far!

Eric W - This is perfect, thank you.

And Norie, it was if D3 is empty.

Thanks again all
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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