Help with code to Add Rows

MadMatt

New Member
Joined
Sep 27, 2006
Messages
12
HI All, I'm trying to merge 2 command butons from the same workbook but on different sheets. The command button work fine by them self the code for them is below

Private Sub CommandButton1_Click()
Rows("11").Select
Selection.Insert Shift:=xlDown
Rows("11").Select

End Sub

Private Sub CommandButton1_Click()
Sheets("Punch Detail").Select
Application.CutCopyMode = False
Rows("5:5").Select
Selection.Copy
Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
End Sub

I'm not to good at code yet but I tried this but it won't work the code is below.

Private Sub CommandButton1_Click()
Rows("11").Select
Selection.Insert Shift:=xlDown
Rows("11").Select
Sheets("Punch Detail").Select
Application.CutCopyMode = False
Rows("5:5").Select
Selection.Copy
Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
End Sub

Could somone please help me with this code as I'm not good at it yet and don't no many of the functions in excel.

Thanks Matt
 
Hi Jindon got it worked out with this code. Thankyou for your help!

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim cell As Range
Rows(11).EntireRow.Insert
For Each cell In Intersect(ActiveSheet.UsedRange, Selection.Offset(-1, 0).EntireRow)
If cell.HasFormula Then
cell.Copy cell.Offset(1, 0)
End If
Next
Application.ScreenUpdating = True
With Sheets("Punch Detail")
.Rows(5).Insert
.Rows(4).Copy .Cells(5, 1).End(3)(2)
End With
End Sub
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,214,870
Messages
6,122,021
Members
449,060
Latest member
LinusJE

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