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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

bebo021999

Well-known Member
Joined
Jul 14, 2011
Messages
1,839
Office Version
  1. 2016
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:

SIPRIAN

New Member
Joined
Nov 10, 2016
Messages
36
Its not working on Microsoft365.
On Office2019 is giving an error
 

Attachments

  • Capture.PNG
    Capture.PNG
    4.6 KB · Views: 3

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
65,556
Office Version
  1. 365
Platform
  1. Windows
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.
 

SIPRIAN

New Member
Joined
Nov 10, 2016
Messages
36
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: 3

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
65,556
Office Version
  1. 365
Platform
  1. Windows
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
 

SIPRIAN

New Member
Joined
Nov 10, 2016
Messages
36
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.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
65,556
Office Version
  1. 365
Platform
  1. Windows
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.
 

SIPRIAN

New Member
Joined
Nov 10, 2016
Messages
36
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)
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
65,556
Office Version
  1. 365
Platform
  1. Windows
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)?
 

Forum statistics

Threads
1,176,504
Messages
5,903,431
Members
435,029
Latest member
excelvbanoob420

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
Top