Macro By Click to clear all data in a specific row except formulas

mostafaelkady98

New Member
Joined
Aug 18, 2022
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Hi all, I am new to VBA macros
I am trying to create a macro that adds a row at the end of specific rows while clearing the values and keeping the formulas.
Sub RectangleAddRow_Click()

With Worksheets("Lintel Calculation")

.Range("TotalLintelVolume").Offset(-2).EntireRow.Copy
.Range("TotalLintelVolume").Offset(-1).EntireRow.Insert Shift:=xlShiftDown
On Error Resume Next
.Range("TotalLintelVolume").Offset(-2).SpecialCells(xlCellTypeConstants).Value = ""
Application.CutCopyMode = False
On Error GoTo 0

End With

End Sub
but when I click it clears all cells in my sheet, not the specified row only
Thanks a lot, best regards
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
1.jpg

when I press "Add type" it should Add a new Row at Row 13 and clear all the content of row 13 only (but it clears all the sheet data)
 
Upvote 0
I found the solution the code should be as follows

Sub RectangleAddRow_Click()

With Worksheets("Lintel Calculation")

.Range("TotalLintelVolume").Offset(-2).EntireRow.Copy
.Range("TotalLintelVolume").Offset(-1).EntireRow.Insert Shift:=xlShiftDown
On Error Resume Next
.Range("TotalLintelVolume").Offset(-2).EntireRow.SpecialCells(xlCellTypeConstants).Value = ""
Application.CutCopyMode = False
On Error GoTo 0

End With

End Sub
The problem was that I didn't specify the row "EntireRow"
 
Upvote 0
Solution

Forum statistics

Threads
1,214,784
Messages
6,121,539
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top