Consulting

Results 1 to 4 of 4

Thread: Help with clear contents

  1. #1

    Help with clear contents

    I need to clear contents of the row from "A3" to "D3". This is fixed it will not change.

    How ever as the user inputs data I need to clear contents verically and this will change depending on how much data the user inputs. It could be "A3" to "D16" the last cell could be any number.


    Here is what I tryed.

    [vba]
    Sub Clear()
    With Range("A3")
    .End(xlToRight).Offset(0, 0).Cells.ClearContents
    .End(xlDown).Offset(0, 0).Cells.ClearContents
    End With
    End Sub
    [/vba]


    This seems to be close it clears the last cell in one row and it clears the last cell in the first column.

  2. #2
    VBAX Regular
    Joined
    Oct 2010
    Posts
    73
    Location
    Hi,

    See if this works.

    Sub Clear() 
      Range("A3:D" & Range("D65536").End(xlUp).Row).ClearContents
    End Sub
    

    My Time is valuable. The forum's time is valuable.
    So take time to say "Thanks"

    As with all programs there may be an easier way!
    CharlesH

  3. #3
    Yes it works perfect. However, I do not understand the logic.

    Thanks,

  4. #4
    VBAX Regular
    Joined
    Oct 2010
    Posts
    73
    Location
    HI,

    The code looks for the last used cell in column "D" and when you specify the range as I did the code now says "Clear the Contents" in
    Range("A3:D and the last used cell in column D")
    'So if the last used cell in column D is "16" then the code will 
    ' ClearContents in 
    Range("A3:D16")

    Hope this helps
    My Time is valuable. The forum's time is valuable.
    So take time to say "Thanks"

    As with all programs there may be an easier way!
    CharlesH

Posting Permissions

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