clear content of F9 and F10 cell if D9 has value1205

SIPRIAN

New Member
Joined
Nov 10, 2016
Messages
36
HI,

I'm trying to clear content of F9 and F10 cell if D9 has value1205.
I used the macro below however, it didn't work


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$9" Then
If Target.Value = UCase("1205") Then Sheets("Sheet2").Range("f9:F10 ").ClearContents ""
End If
End Sub


I have Microsoft 365

Thank you for your time
 
These are the other values
12304
12039
6598
1190
1190
11410
10096
1051
1115
10260
10002
10002
1066
10554
1066
9952
10209
9952
1066
9952
9952
10209
9952
1190
1043


I can add the above values in B21 to B45 if they can not be added to the script

this VBA is not working with Microsoft 365
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$9" and Target.Value = 1205 Then Range("F9:F10").ClearContents
End Sub

This VBA is working with MIcrosioft365
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("d:d")) Is Nothing Then
If Target = 1205 Then
Range("F" & Target.Row).Clear
End If
End If
End Sub

i'm using what is working
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Are they in cells B21:B45 on the SAME sheet that you are deleting from, or on a different sheet?
Do you only want to look ONLY at row 9, or other rows too?
 
Upvote 0
If it is on the same sheet, and that you want it to apply to ANY row (like the second code that you said works does), then this should do what you want:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Not Intersect(Target, Range("D:D")) Is Nothing Then
        If Application.WorksheetFunction.CountIf(Range("B21:B45"), Target.Value) > 0 Then
            Range("F" & Target.Row).Clear
        End If
    End If
    
End Sub
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,214,795
Messages
6,121,624
Members
449,041
Latest member
Postman24

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