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
 

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,647
Messages
5,597,363
Members
414,139
Latest member
okela0

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
Top