Two Cell Change Worksheet Macro - Private Sub Worksheet_Change(ByVal Target As Range)

Srivatsal

New Member
Joined
Dec 4, 2017
Messages
7
Hi,

Need help I am new pretty new to VBA, created a worksheet it is working for 1 condition but I tried a lot but unable to make it work for the second condition in the same worksheet.

Background: The first code pasted below calls the I need to below code to call a macro when the condition1 cell changes to "Initaited" similarly I want it to call second macro in general module when the condition1 cell changes to "Completed"

PLEASE HELP

Private Sub Worksheet_Change(ByVal Target As Range)
Dim LR As Long
LR = Range("N" & Rows.Count).End(xlUp).Row
'This assumes a Header Row in N1
If Not Intersect(Target, Range("N2:N" & LR)) Is Nothing Then
' If Target.Value = "Initiated" Then
Call Create_Mail_From_List(Target)
' End If
End If
End Sub

[TABLE="width: 271"]
<tbody>[TR]
[TD="align: center"]Name
[/TD]
[TD="align: center"]Email address
[/TD]
[TD="align: center"]Condition1
[/TD]
[TD="align: center"]Condition2
[/TD]
[/TR]
[TR]
[TD="align: center"]User1
[/TD]
[TD="align: center"]1@c.com
[/TD]
[TD="align: center"]Initiated
[/TD]
[TD="align: center"]Completed
[/TD]
[/TR]
[TR]
[TD="align: center"]User1
[/TD]
[TD="align: center"]2@c.com
[/TD]
[TD="align: center"]Initiated
[/TD]
[TD="align: center"]Completed
[/TD]
[/TR]
[TR]
[TD="align: center"]User1
[/TD]
[TD="align: center"]3@c.com
[/TD]
[TD="align: center"]Initiated
[/TD]
[TD="align: center"]Completed
[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Maybe this is what you want:
Modify to your needs. Or explain more.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LR As Long
LR = Range("N" & Rows.Count).End(xlUp).Row
'This assumes a Header Row in N1
If Not Intersect(Target, Range("N2:N" & LR)) Is Nothing Then
If Target.Value = "Initiated" Then Call Bob
If Target.Value = "Completed" Then Call George
End If
End If
End Sub
 
Upvote 0
Maybe this is what you want:
Modify to your needs. Or explain more.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LR As Long
LR = Range("N" & Rows.Count).End(xlUp).Row
'This assumes a Header Row in N1
If Not Intersect(Target, Range("N2:N" & LR)) Is Nothing Then
If Target.Value = "Initiated" Then Call Bob
If Target.Value = "Completed" Then Call George
End If
End If
End Sub

Tried it but does not work Unfortunatley... If anybody could help me on this please.
 
Upvote 0
[TABLE="class: cms_table, width: 271"]

<tbody>[TR]
[TD="align: center"]Name[/TD]
[TD="align: center"]Email address[/TD]
[TD="align: center"]Condition1[/TD]
[TD="align: center"]Condition2[/TD]
[/TR]
[TR]
[TD="align: center"]User1[/TD]
[TD="align: center"]1@c.com[/TD]
[TD="align: center"]Initiated[/TD]
[TD="align: center"]Completed[/TD]
[/TR]
[TR]
[TD="align: center"]User1[/TD]
[TD="align: center"]2@c.com[/TD]
[TD="align: center"]Initiated[/TD]
[TD="align: center"]Completed[/TD]
[/TR]
[TR]
[TD="align: center"]User1[/TD]
[TD="align: center"]3@c.com[/TD]
[TD="align: center"]Initiated[/TD]
[TD="align: center"]Completed[/TD]
[/TR]
</tbody>
[/TABLE]
Lets assume the colums are "N" for condition1 and column "S" for condition2 in the above case. Please help guys!!
 
Upvote 0
Try this:

Modify calling Macro name.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 14 Or Target.Column = 19 Then
If Target.Column = 14 And Target.Value = "Initiated" Then Call Bob
If Target.Column = 19 And Target.Value = "Completed" Then Call George
End If
End Sub
 
Upvote 0
Try this:

Modify calling Macro name.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 14 Or Target.Column = 19 Then
If Target.Column = 14 And Target.Value = "Initiated" Then Call Bob
If Target.Column = 19 And Target.Value = "Completed" Then Call George
End If
End Sub

This is also not working - Its giving a compile error on "Exit Sub" and highlighting yellow on the first line "Private Sub Worksheet_Change(ByVal Target As Range)"

[IMG]C:\Users\lakshmis\Desktop\Macro[/IMG]
 
Upvote 0
If I understand you correctly you want:

If you enter "Initiated" in column "N" you want to run a macro
If you enter "Completed" in column "S" you want to run a macro

So I have call Bob
Call George

I do not know the names of the Macros you want to run so you must change George and Bob to the Macro name you want to run

If this is not what you want then you need to explain more
 
Upvote 0

Forum statistics

Threads
1,224,836
Messages
6,181,252
Members
453,028
Latest member
letswriteafairytale

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