rjbinney
Active Member
- Joined
- Dec 20, 2010
- Messages
- 279
- Office Version
- 365
- Platform
- Windows
This seems really simple.
When I "record" the Macro, it works. When I repeat, or try anything with my (limited) VBA skills, it does not.
I have two worksheets.
I need a macro where the user clicks on a cell in Sheet A, and Excel adds a new row immediately below that row in Sheet A AND Sheet B.
So if the user selects SheetA!G12 and runs the macro, a row is inserted between SheetA!Row 12 and 13, and ALSO SheetB!Row 12 and 13; if the user selects SheetA!K47 and runs the macro, a row is inserted between SheetA!Row 47 and 48, and ALSO between SheetB!Row 47 and 48, and so on.
I've tried:
Sheets("A").Activate
Sheets(Array("A", "B")).Select
ActiveCell.Offset(1, 0).EntireRow.Select
Selection.EntireRow.Insert
Sheets("A").Activate
Sheets(Array("A", "B")).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.EntireRow.Insert
Sheets(Array("A", "B")).Select
Sheets("A").Activate
ActiveSheet.Cells(ActiveCell.Row, 1).Select
Selection.Offset(1, 0).Select
Application.CutCopyMode = False
Selection.EntireRow.Insert
When I run any of these, it selects both sheets, but only adds the new row to Sheet A, not Sheet B.
It's staring me in the face, but I'm stuck.
When I "record" the Macro, it works. When I repeat, or try anything with my (limited) VBA skills, it does not.
I have two worksheets.
I need a macro where the user clicks on a cell in Sheet A, and Excel adds a new row immediately below that row in Sheet A AND Sheet B.
So if the user selects SheetA!G12 and runs the macro, a row is inserted between SheetA!Row 12 and 13, and ALSO SheetB!Row 12 and 13; if the user selects SheetA!K47 and runs the macro, a row is inserted between SheetA!Row 47 and 48, and ALSO between SheetB!Row 47 and 48, and so on.
I've tried:
Sheets("A").Activate
Sheets(Array("A", "B")).Select
ActiveCell.Offset(1, 0).EntireRow.Select
Selection.EntireRow.Insert
Sheets("A").Activate
Sheets(Array("A", "B")).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.EntireRow.Insert
Sheets(Array("A", "B")).Select
Sheets("A").Activate
ActiveSheet.Cells(ActiveCell.Row, 1).Select
Selection.Offset(1, 0).Select
Application.CutCopyMode = False
Selection.EntireRow.Insert
When I run any of these, it selects both sheets, but only adds the new row to Sheet A, not Sheet B.
It's staring me in the face, but I'm stuck.