vba code for deleting same row in 2 sheets

Mr Novice

New Member
Joined
Jan 2, 2018
Messages
4
Hi guy's

Can someone help me with a code to delete same entire rows on 2 sheets?
i.e. delete entire row in Sheet1 which deletes the same entire row in Sheet2


Note I already have the following code for other tasks in this Workbook -
Sheet1 Module

Public LastSelect As Range


Private Sub Worksheet_Activate()
Me.Range(Sheet2.LastSelect.Address).Select
End Sub


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set LastSelect = Target
End Sub


Sheet2 Module
Public LastSelect As Range


Private Sub Worksheet_Activate()
Me.Range(Sheet1.LastSelect.Address).Select
End Sub


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set LastSelect = Target
End Sub



Many Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Sheet1 Module
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long
r = Target.row
Sheets("Sheet2").Rows(r).EntireRow.Delete
End Sub

If the third row of sheet1 is deleted, third row of sheet2 will be deleted.
Hope this helps.
 
Last edited:
Upvote 0
Thanks Takae
The deleting part worked but it messed up the calculation formulas in the cells on Sheet2.
Sheet2 has formulas that works off the same cell in Sheet1.
 
Upvote 0
Regardless of manual or VBA, it is assumed that rows are deleted, so the formula must be changed.
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,580
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