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
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$9" and Target.Value = 1205 Then Sheets("Sheet2").Range("F9:F10").ClearContents
End Sub
 
Last edited by a moderator:
Upvote 0
Its not working on Microsoft365.
On Office2019 is giving an error
 

Attachments

  • Capture.PNG
    Capture.PNG
    4.6 KB · Views: 5
Upvote 0
Do you have a sheet named "Sheet2" in your workbook?
If not, update the name of the sheet in the code to match where you are trying to update this.
 
Upvote 0
Please see attached. I would like to use this macro on microsoft365.
this pic is from office2019
 

Attachments

  • Capture.PNG
    Capture.PNG
    62.2 KB · Views: 5
Upvote 0
It all looks like it is on the same sheet, so you shouldn't need the sheet reference, i.e.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$D$9" and Target.Value = 1205 Then Range("F9:F10").ClearContents
End Sub
 
Upvote 0
Do you also have VBA code in the Sheet2 module? - the vba was in Sheet1 - Thank you
I'm trying to add more values for D9, but it didn't work

If Target.Value = UCase("1205", "12304") Then Sheets("Sheet2").Range("f9:F10 ").ClearContents ""

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.
 
Upvote 0
Let's just focus on one thing at a time here (by the way, using UCASE on numbers is pointless, it has not effect on it).

Did you try the revised code in my last post?

How many sheets are in this workbook?

If you have Sheet1 and Sheet2, please post the current VBA code in each of those sheet modules.
 
Upvote 0
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 trying to change the code to add more values(12304, 12039,... etc)
 
Upvote 0
Note that your two codes are NOT the same.

First one is ONLY looking at cell D9, and is only clearing cells F9 and F10.
Second one is looking at ANY cell in column D, and clearing just column F in the same row.

So they are not quite doing the same thing.

Exactly how many values do you have to check?
If more than a handful, you are going to need to store that list somewhere.

Where is that going to be?
In a list on a sheet somewhere (if so, exactly where)?
Or do you want to store them in an array in VBA (might be a limit to how many you can store)?
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,780
Members
449,049
Latest member
greyangel23

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