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

Status
Not open for further replies.

TashaWard

New Member
Joined
Dec 1, 2017
Messages
5
Hi,

I have a worksheet which has a button for users to press to add a new line underneath the active cell
It copies the existing row and pastes underneath after asking for permission

I need to clear the contents from column B and C on the new row only
Specific cell references can't be used as they may add multiple new lines, so I'm looking to use active cell, but I don't know how to refer to the row below and only 2 cells of that row

this is my existing code if someone has a suggestion on how to clear what I'm looking to?

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
    Range(ActiveCell, ActiveCell.1(xlDown).1(xlToRight)).Select
    ThisWorkbook.Worksheets("RequisitionForm").Protect ("*")
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
If this happens again, please click the report button, enter Duplicate in the message box along with a link to the original thread.
Thanks
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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