Add Code when new data is added

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
I'm using the following code on my worksheet page and want to know how I can expand this so that if I insert data in row 2 it will add another line as shown.

If Target.Address = "$A$1" Then
Call Ghostbusters
End If

Add this:

If Target.Address = "$B$1" Then
Call Ghostbusters
End If
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi, try something like this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A1:B1")) Is Nothing Then
    Call Ghostbusters
End If
End Sub
 
Upvote 0
Sorry i meant that the data would be added to row 2. I updated the code to reflect this, but i think it is now preventing me from using the code that adds a row. Is there a way to say Range (A1:LR)
and the define LR. So that it would look and A1 and then count every row under that, that has a value in A
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lstRow As Long
lstRow = Range("A" & Rows.Count).End(xlUp).Row
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A1:A" & lstRow)) Is Nothing Then
    Call Ghostbusters
End If
End Sub

OR

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A:A")) Is Nothing Then
    Call Ghostbusters
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,545
Messages
6,120,128
Members
448,947
Latest member
test111

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