Macro to add and delete lines

Constellation8

New Member
Joined
Jun 24, 2008
Messages
5
Dear Excel Helpers,

I'm creating a template which has links and formulas from one (source)worksheet to other worksheets within a workbook.

For this template, I am trying to create a macro that adds a line above the same row for each worksheet. I can do this for a specified row (ie. row 44). Can I do this: when the user of the template highlights a row from the source worksheet and inserts a row, can the VBA macro then find the same numbered row in other worksheets and add a line? Thus, all the worksheets will have the same rows.

For deleting a row, I found how to select a row or cell and delete the entire row (below):
If TypeName(Selection) = "Range" Then
Selection.EntireRow.Delete
End If

I then want to automatically delete the same rows (which will have #REF! across the row) in the other worksheets. Any ideas on this?

My goal is for a user to update the source worksheet and the other worksheets with the formulas will be updated automatically.

Thanks for any suggestions you provide.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
maybe you can do something like this; instead if deleting the row from the template manually, just run the macro below... this macro will delete the selected row, and the same row number from all the worksheets:

Code:
Sub Macro1()
    Dim r As Long: r = Selection.Row
    Dim c As Long: c = Selection.Column
    
    For Each sh In Worksheets
        sh.Cells(r, c).EntireRow.Delete
    Next sh
    
End Sub
 
Upvote 0
Thank you so much, Iggydarsa.

For an extra challenge, do you think there's a way to highlight more than one row and delete all the rows on each sheet?
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

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