Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Nov 2003
    Location
    Tampa, Florida, USA
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Clear Numeric and Blank Cells (Excel 2003)

    I am trying to clear the contents of cells in columns A to M when the corresponding row in Column A is blank or numeric
    The code I have is:

    Sub Row_Clear2()
    Dim a As Long
    Dim b As Long
    Dim LClearCells As String
    'data will cleared in columns A to M when Column A is blank or numeric
    LClearCells = "A" & a & ":" & "M" & a

    a = Range("A300").End(xlUp).Row
    For b = a To 2 Step -1
    If IsNumeric(Range("A" & ) Or Range("A" & = "" Then
    Range(LClearCells).ClearContents
    End If
    Next b
    End Sub

    The code fails at "Range(LClearCells).ClearContents"
    Can you help?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Clear Numeric and Blank Cells (Excel 2003)

    You assign a value to LClearCells outside of the loop, even before a has been assigned a value. You should assign LClearCells inside the loop and use the loop index b instead of the loop limit a:
    <code>
    Sub Row_Clear2()
    Dim a As Long
    Dim b As Long
    Dim LClearCells As String

    a = Range("A300").End(xlUp).Row
    For b = a To 2 Step -1
    If IsNumeric(Range("A" & ) Or Range("A" & = "" Then
    'data will be cleared in columns A to M when Column A is blank or numeric
    LClearCells = "A" & b & ":M" & b
    Range(LClearCells).ClearContents
    End If
    Next b
    End Sub</code>

  3. #3
    Star Lounger
    Join Date
    Nov 2003
    Location
    Tampa, Florida, USA
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Clear Numeric and Blank Cells (Excel 2003)

    Thanks Hans .I'm just not thinking today

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •