Consulting

Results 1 to 3 of 3

Thread: clear last line

  1. #1

    clear last line

    Hi Guys

    I need some help with a macro problem i have please.

    I have a userform with a command button which clears the last line in the list box.
    It works OK but deletes the formular as well.

    I have another one that leaves the formular but clears the whole list box rather than one at a time.

    Can you please help me combine the two into one.

    ..............................
    Sub clear()
    Dim x As Long
    With Sheets("database")
    x = .Cells(.Rows.Count, 1).End(xlUp).Row
    .Cells(x, 1).EntireRow.ClearContents
    End With
    End Sub
    ...............................
    Sub clear()
    Dim C As Range
    For Each C In Sheet1.Range("Database_range")
    If Not C.HasFormula Then C.ClearContents
    Next C
    End Sub
    ..................................

    Can you please help

  2. #2
    VBAX Expert
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    774
    Location
    Hi Keith,

    Maybe you could edit your first macro as below:
    Sub clear()    
        Dim x As Long
        
        With Sheets("database")
            x = .Cells(.Rows.Count, 1).End(xlUp).Row
            .Cells(x, 1).EntireRow.SpecialCells(xlConstants).ClearContents
        End With
    End Sub
    If things don't change they stay the same
    Quite often there is a picnic problem (problem in chair not in computer)
    "We were not told it was impossible, so we did it."

  3. #3
    Hi Georgiboy

    It works great and i really appreciate you helping.

    Regards

    Keith (fellow Brit living in NZ)

Tags for this Thread

Posting Permissions

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