Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a worksheet that contains numbers, text, blank cells, a text
entry of x, and #N/A entered as =na(), i.e. an error value. I would like to select (highlight) a range, say A1:D4 and run a macro that clears the contents of only those cells whose value is x. See sample worksheet below. A B C D 1 400 x #N/A text1 2 x text2 200 3 text3 300 x 4 #N/A x text2 500 5 6 text2 20 10 7 - text3 #N/A 500 8 - 300 text1 When I select A1:D4 and run the following macro, it works except for one detail that I can't figure out. It clears not only the contents of those cells containing only an x but those cells containing #N/A as well! I would like the macro to not clear the #N/A cells nor any other cells unless they contain only an x. Sub ClearContentsX() On Error Resume Next Dim s As String s = "x" For Each r In Selection If r.Value = s Then r.ClearContents End If Next r End Sub What am I doing wrong? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro to clear contents and put an X | Excel Discussion (Misc queries) | |||
Clear Contents Macro | Excel Programming | |||
Macro to clear range contents when cell contents are changed by us | Excel Programming | |||
Clear Contents Macro | Excel Programming | |||
Need macro to clear contents | Excel Programming |