insert row EVENT

RSXchin

Well-known Member
Joined
Oct 23, 2010
Messages
758
If I insert a row at row 10 on sheet 1, how do I automatically insert a row at row 10 on sheet 2?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
If you select both sheets at the same time...

Select Sheet1
Press and Hold the CTRL Key
Select Sheet2
Release the CTRL Key
Insert Row 10

Then right click either sheet's tab and choose "Ungroup Sheets"


Hope that helps.
 
Upvote 0
I was talking about a macro event. Here is how I got around it
PHP:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Columns.Count > 100 Then
        MsgBox "row"
    End If
End Sub
 
Upvote 0
Unfortunately there is no event that captures Insert Row...Persay...

The Change event IS triggered by inserting/deleting Rows.
However, it doesn't offer any method of knowing if it was triggered by row insertion/deletion.
And also no way of knowing WHICH row was inserted/deleted.


Here's a trick you might use,
Which is by no means foolproof.

Put any value (like "Last") in column A (or any column of your choice)
at a row FAR below your actual last used row.
Make note of the row you put it in.

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
lr = Cells(Rows.Count, "A").End(xlUp).Row
MyRow = 500 'This is the row you put "Last" in
Select Case lr
    Case Is > MyRow
        If Target.Columns.Count = Columns.Count Then
            MsgBox "A row was inserted at Row # " & Target.Row
        End If
    Case Is < MyRow
        If Target.Columns.Count = Columns.Count Then
            MsgBox "Row # " & Target.Row & " Was Deleted"
        End If
    Case Else
End Select
End Sub
 
Last edited:
Upvote 0
I like that Jonmo. I would add in a
Code:
Case Is = MyRow
    If Target.Columns.Count = Columns.Count Then
        MsgBox "A row cleared but not deleted at # " & Target.Row
    End If

is that good?
 
Upvote 0
Not bad, but it wasn't necessarily cleared...
It might have had values added into the row...
Perhaps test if target.value = ""
 
Upvote 0
if you are changing a value, then the target.columns.count CAN'T be columns.count.

edit:.... unless it was a copy-paste
 
Upvote 0
You can change multiple cells at a single time...

Highlight any row.
Type any value
Hold the CTRL Key
Press Enter


Discovering flaw in my previous post...

Perhaps test if target.value = ""
would have to be
Target(1).Value = ""
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,855
Members
452,948
Latest member
UsmanAli786

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