Help On Worksheet Change Event

auto

Board Regular
Joined
May 20, 2012
Messages
53
i am having a sheet1 where each time i am getting an email from someone the vba brings some info in my sheet one info in first available cell in column A and the other info next to it on column B,
now i want to make that each time i am getting new info then a macro should be fired, after the macro is finnish with the job, erase the data,
well can someone help me with a code on that?
i tried this but this workes only if i delete a cell not when it get a value

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells = Value Then
Application.Run "PERSONAL.XLSB!mymacro"
Else
Exit Sub
End If
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
i am having a sheet1 where each time i am getting an email from someone the vba brings some info in my sheet one info in first available cell in column A and the other info next to it on column B,
now i want to make that each time i am getting new info then a macro should be fired, after the macro is finnish with the job, erase the data,
well can someone help me with a code on that?
i tried this but this workes only if i delete a cell not when it get a value

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells = Value Then
Application.Run "PERSONAL.XLSB!mymacro"
Else
Exit Sub
End If
End Sub
Try:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
       Application.Run "PERSONAL.XLSB!mymacro"
End Sub
 
Upvote 0
the problem with this code is, that i want after the macro is finish doing the job it suppose to delete the cells that triggered the macro, so when the cells will get deleted the macro fires again, which is not good because there is no data there anymore.
 
Upvote 0
the problem with this code is, that i want after the macro is finish doing the job it suppose to delete the cells that triggered the macro, so when the cells will get deleted the macro fires again, which is not good because there is no data there anymore.
Try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)        Application.Run "PERSONAL.XLSB!mymacro"
       Application.enableEvents = false
       Target.Cells.Delete       
       Application.enableEvents = True
End Sub
 
Upvote 0
but the problem is that, i am getting info in to cells, let me give you some details so you will catch up where the problem is, and see how we can handle with it.

we have sheet1 in column A will get filled the "name" column B will get filled the "Phone number",
now, Name & phone must be the same, lets call it target, as of now when the first cell is entered let say "name" it fires the macro, but phone cant come in to the sheet, because excel fired a macro, so what happens is, when the macro is Finnish then "phone" come in to the sheet, and fires the macro again, without having now the "name" because it was deleted after process,

so what i want is this, is possible to make that when a cell from column A gets info it should wait for the cell in Column B next to it, it should also get info, then the macro should trigger, and after its finish it should delete the info from both, is possible to do that?
 
Upvote 0
See if this does what you want:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then
    MsgBox "Please change only one cell at a time starting in column A, then column B"
    Application.EnableEvents = False
    Target.Cells.ClearContents
    Application.EnableEvents = True
    Exit Sub
End If
If Not Intersect(Target, Columns("B")) Is Nothing Then
    Application.Run "PERSONAL.XLSB!mymacro"
    Application.EnableEvents = False
    Target.ClearContents
    Target.offset(0,-1).ClearContents
    Application.EnableEvents = True
End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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