Simple ClearContents not working

ColinCoady

New Member
Joined
Mar 21, 2019
Messages
35
I can't figure out why this won't work. Can someone take a look?

Code:
Private Sub ClearContents()
Worksheets("Costing").Activate
If Cells(7, 5).Value = "Other %" Then Cells(7, 7).ClearContents
End Sub
 

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)
You do understand:

Code:
[LEFT][COLOR=#333333][FONT=monospace]If Cells(7, 5).Value = "Other %" Then Cells(7, 7).ClearContents
[/FONT][/COLOR][/LEFT]

Means if Row(7) column(5) And then clear Row(7) Column(7)

These are not the same.
 
Upvote 0
What is the value in E7 on the Costing sheet?
 
Upvote 0
Colin, check that the string in E7 has no leading or trailing spaces, also check that it is only one space between the r and the %.
 
Upvote 0
The value in E7 is from a Data validation list with 5 choices. One of the choices is "Other %"
I changed "Other %" to "Other%" (no space) and changed the code accordingly. Still doesn't want to work.
Still missing something - just not sure what. Any thoughts?
Thanks MARK858 and Fluff
-Colin
 
Upvote 0
None from me at the moment as long as it is G7 being cleared.

Just out of interest can you copy and paste (Please copy/paste it, don't retype it) the result that appears in your immediate window if you run the code below.

Code:
Sub testit()
Debug.Print "| &"; Cells(7, "E").Value; "& |", Len(Cells(7, "E").Value)
End Sub
 
Last edited:
Upvote 0
Then I am afraid I have no ideas at the moment (if you don't have any other code taking effect and no protection, which would have produced an error) as your code is clearing G7 for me.
 
Upvote 0
Hello,

You could test following

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address <> "$E$7" Then Exit Sub
  If Target = "Other %" Then Target.Offset(0, 2).ClearContents
End Sub

Hope this will help
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,797
Members
449,048
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