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
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,158
    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
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2401, Build 17231.20084

  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
  •