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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
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,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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