HELP: How to insert and delete rows in multiple sheets.

nardlje80

New Member
Joined
May 12, 2015
Messages
8
Good day! I have an electronic class record with not less than 10 sheets. What I want to happen is that, when I insert row in first sheet, the same row will be inserted in the rest of the worksheets and when I delete a row, it will also be deleted in the rest of the sheets. I am not good in macro and barely understands codes. I tried the code below but it only add row in multiple sheets when I do a right-click. The problem is that when I delete a row in the first page, it do not delete in the rest of the sheets. Furthermore, I wish that the row inserted will copy the formula of the cells in the row where it is inserted. I hope anybody can help me. here's my code:

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Dim lngRow As Long
Dim ws As Worksheet
If Target.Column = 1 Then
Cancel = True
lngRow = ActiveCell.Row
For Each ws In Worksheets
Select Case ws.Name
Case "Sheet8", "Sheet9" 'adjust tabsheet names here to exclude sheets
'do Nothing
Case Else
ws.Rows(lngRow).Insert
End Select
Next ws
End If
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Macros which run "Automatically" are triggered by an Excel recognizable event. Row insert and Row delete are not Excel recognizable events for purpose of triggering VBA code, other than the change event. If the change event is used to trigger your code it there is no way to tell if the change is from an row insert or row delete action. I think your double-click is probably going to be your best bet.
 
Upvote 0

Forum statistics

Threads
1,213,530
Messages
6,114,163
Members
448,554
Latest member
Gleisner2

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