PDA

View Full Version : [SOLVED:] clear last line



keith barnes
06-27-2022, 11:37 PM
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

georgiboy
06-27-2022, 11:48 PM
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

keith barnes
06-28-2022, 12:02 AM
Hi Georgiboy

It works great and i really appreciate you helping.

Regards

Keith (fellow Brit living in NZ):yes