Announcement

Collapse
No announcement yet.

Macro To Clear Cells

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Macro To Clear Cells

    I am trying to see if there can be a marco that will (for example) look in the range of cells d2:f22 and if there is a number in a cell-do nothing but if there is a non-number - clear that cell.

    Anyone know how to write this??

    thanks for any help

    Frank

  • #2
    Welcome to the OzGrid Forum!

    Try

    Sub DeleteStuff()
    Dim c As Range
    For Each c In Range("D2:F22")
    If Not IsNumeric(c) Then c.ClearContents
    Next c
    End Sub
    Please do not U2U (private message) me directly for questions that should be posted to the forum; any such U2Us will be ignored.

    Comment


    • #3
      I can't thank you enough!
      What a huge help



      is it also possible to do the same clear from a "highlighted" thus variable section of the worksheet?

      Thanks again!!

      Comment


      • #4
        Glad to have been able to help. To change the macro so it works with a "highlighted" area of the worksheet, just replace
        Range("D2:F22")
        with
        Selection
        in the code.
        Please do not U2U (private message) me directly for questions that should be posted to the forum; any such U2Us will be ignored.

        Comment

        Working...
        X