Insert Row Automatically between 2 sheets

renaoh

New Member
Joined
Jun 3, 2008
Messages
3
I would much appreciate help from everyone. I do not have much experience on Excel, please give me some simple instructions . I have one workbook with two worksheets, Sheet 1 and Sheet 2. When I insert a row in Sheet 1, I would also like a row to be inserted in Sheet 2 automatically. How can I do that?
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Copy and paste this code into the worksheet code module. Do the following: right click the tab name for your Sheet1 and click 'View Code'. Paste the code into the empty code window that opens up. Close the code window to return to your sheet. Insert a row in Sheet1.
VBA Code:
Dim lRow As Long

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim lRow2 As Long
    lRow2 = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    If lRow2 > lRow Then
        Sheets("Sheet2").Range("A" & Target.Row).EntireRow.Insert
    End If
End Sub
 
Upvote 0
Copy and paste this code into the worksheet code module. Do the following: right click the tab name for your Sheet1 and click 'View Code'. Paste the code into the empty code window that opens up. Close the code window to return to your sheet. Insert a row in Sheet1.
VBA Code:
Dim lRow As Long

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim lRow2 As Long
    lRow2 = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    If lRow2 > lRow Then
        Sheets("Sheet2").Range("A" & Target.Row).EntireRow.Insert
    End If
End Sub

Good morning, Mumps. Thank you for the instant reply and you have been very helpful. I applied the codes given and it works !!!.

I was thinking in the event that I need to delete some rows later on, how can I do that too? Hope you don't mind me asking again. Thank you.
 
Upvote 0
Try:
VBA Code:
Dim lRow As Long

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim lRow2 As Long
    lRow2 = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    If lRow2 > lRow Then
        Sheets("Sheet2").Range("A" & Target.Row).EntireRow.Insert
    ElseIf lRow2 < lRow Then
        Sheets("Sheet2").Rows(Target.Row).Delete
    End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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