VBA for deleting data in row but not formulas

Solved/Closed
Debs269 Posts 21 Registration date Monday 15 October 2012 Status Member Last seen 18 August 2016 - 15 Oct 2012 à 06:50
Debs269 Posts 21 Registration date Monday 15 October 2012 Status Member Last seen 18 August 2016 - 31 Oct 2012 à 07:24
Hello,

I am working on a spreadsheet where I have to copy data over to a new sheet, once the data is copied I want to delete the data in the row from original sheet, without losing the formulas,

Any help would be much appreciated

Thx


7 responses

TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 555
15 Oct 2012 à 09:20
Hi Debs,

Once you have implemented the code below, select a cell from the row you want to keep the formula's from and run the code.

Sub KeepFormulas()
Dim sRow, lCol As Integer
sRow = ActiveCell.Row
lCol = Cells(sRow, Columns.Count).End(xlToLeft).Column
For Each cell In Range(Cells(sRow, 1), Cells(sRow, lCol))
    If cell.HasFormula = False Then cell.ClearContents
Next cell
End Sub

Best regards,
Trowa