Insert row below, copy above and clear contents of specific column

coconutxyz

New Member
Joined
Feb 26, 2015
Messages
14
[FONT=&quot]i have searched a bit and all i get doesn't really suit what i needed.[/FONT]
[FONT=&quot]Totally new to VBA but what i am trying to achieve is insert a new row below(either highlighting the whole row or just a cell), copy everything above (format, formula, conditional formatting) and then delete content in specific column(E:K) of the newly created row.[/FONT]
[FONT=&quot]Thanks guys![/FONT]
[FONT=&quot]I have this code available and it does clear the content of specific column but i do not want to manually key in the row number.[/FONT]
<code style="font-family: "Courier New", courier, monospace; margin: 0px 2px; padding: 15px; border: 0px; background-color: transparent; border-radius: 2px; word-break: normal; display: block; font-size: 1em; line-height: 16px; overflow: auto;">Sub Insert()

Dim varUserInput As Variant
varUserInput = InputBox("Enter Row Number where you want to
add a row:", _
"What Row?")
If varUserInput = "" Then Exit Sub

RowNum = varUserInput
Rows(RowNum & ":" & RowNum).Insert Shift:=xlDown
Rows(RowNum - 1 & ":" & RowNum - 1).Copy Range("A" &
RowNum)

Dim x As String

x = "E" & varUserInput & ":" & "k" & varUserInput
Range(x).ClearContents

End Sub</code>
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Code:
Sub Insert()
If Selection.Rows.Count <> 1 Then
    MsgBox "Select in one row only."
    Exit Sub
End If
With Selection(1).EntireRow
    .Copy
    .Offset(1).Insert
    Intersect(.Offset(1), [E:K]).ClearContents
End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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