Consulting

Results 1 to 4 of 4

Thread: Solved: Clear worksheet except for Row 1 Macro

  1. #1
    VBAX Mentor
    Joined
    Jan 2009
    Posts
    304
    Location

    Solved: Clear worksheet except for Row 1 Macro

    Can the following code be modified to not delete the Header Row (Row 1)?

    This code clears the entire worksheet (Timeline Data worksheet) if there is data on it, but if it's blank (except for the Header Row 1) it will delete Row 1. I do not want it to every delete Row 1.

    Thanks...

    JimS


    [vba]
    Sub Macro12()

    With ThisWorkbook.Worksheets("Timeline Data")
    x = .UsedRange.Rows.Count
    .Rows("2:" & x).Delete
    End With


    End Sub
    [/vba]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub Macro12()

    With ThisWorkbook.Worksheets("Timeline Data")
    x = .UsedRange.Rows.Count
    if x >= 2 Then .Rows("2:" & x).Delete
    End With

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    [VBA]Sub Macro12()

    With ThisWorkbook.Worksheets("Timeline Data")
    Range(.Range("A2"),.UsedRange.Offset(1,0)).EntireRow.Delete
    End With

    End Sub[/VBA]

  4. #4
    VBAX Mentor
    Joined
    Jan 2009
    Posts
    304
    Location
    Excellent, Thank you - both of you...

Posting Permissions

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