vba to clear contents from 2 cells of newly added row (row number will change)

TashaWard

New Member
Joined
Dec 1, 2017
Messages
5
Hi all,
I have a worksheet with a macro button for user to add a new line
I currently have a code which will ask for permission to add a new line below the active cell, if confirmed it will copy the existing row and past underneath

What I'd like to do is to clear contents from 2 cells in this new row
I can't use specific cell references as users of the sheet may add more than one line so the selection needs to be of the row below active cell, to clear cells in columns B and C

Can someone help tweak this?

This is my current code:
Code:
ThisWorkbook.Worksheets("RequisitionForm").Unprotect ("*")
Dim lRow As Long
    Dim lRsp As Long
    On Error Resume Next


    lRow = Selection.Row()
    lRsp = MsgBox("Insert new line below row " & lRow & "?", _
            vbQuestion + vbYesNo)
    If lRsp <> vbYes Then Exit Sub


    Rows(lRow).Select
    Selection.Copy
    Rows(lRow + 1).Select
    Selection.Insert Shift:=xlDown
    Application.CutCopyMode = False
    Rows(lRow).PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone
    ThisWorkbook.Worksheets("RequisitionForm").Protect ("*")
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
just add the following code at the bottom of your sub:

Code:
Cells(lRow + 1, 2) = ""
Cells(lRow + 1, 3) = ""
 
Upvote 0

Forum statistics

Threads
1,224,830
Messages
6,181,228
Members
453,025
Latest member
Hannah_Pham93

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