VBA Macro: Auto-filling date in following column once a value is added, independently accross same row
up vote
0
down vote
favorite
I would like to preface my question with the fact that I am not a programmer, I know very little to nothing about coding and this may be very easy.
I am a mortgage loan officer and am trying to streamline my application roster. I have a Macro that I got from this life saving site but I would like to understand how I can add some utility. I have columns at the end of my table for "Reviewed," "Sold," and "dead." I have a conditional formatting set when a "y" is added to any of the columns it auto-fills that row with a corresponding color.
When I add that "y," I would also like the following column to add the date the "y" was added.
Right now I am using the following sub to auto-populate the date after the name. How can I amend it to also add the date column P if I add a y to column O, date to column R if I add a "y" to column Q and a date to column T if I add a "y" to column S.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range, B As Range, Inte As Range, r As Range
Set A = Range("A:A")
Set Inte = Intersect(A, Target)
If Inte Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each r In Inte
If r.Offset(0, 1).Value = "" Then
r.Offset(0, 1).Value = Date
End If
Next r
Application.EnableEvents = True
End Sub
Thank you for your time and consideration.
excel vba
New contributor
add a comment |
up vote
0
down vote
favorite
I would like to preface my question with the fact that I am not a programmer, I know very little to nothing about coding and this may be very easy.
I am a mortgage loan officer and am trying to streamline my application roster. I have a Macro that I got from this life saving site but I would like to understand how I can add some utility. I have columns at the end of my table for "Reviewed," "Sold," and "dead." I have a conditional formatting set when a "y" is added to any of the columns it auto-fills that row with a corresponding color.
When I add that "y," I would also like the following column to add the date the "y" was added.
Right now I am using the following sub to auto-populate the date after the name. How can I amend it to also add the date column P if I add a y to column O, date to column R if I add a "y" to column Q and a date to column T if I add a "y" to column S.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range, B As Range, Inte As Range, r As Range
Set A = Range("A:A")
Set Inte = Intersect(A, Target)
If Inte Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each r In Inte
If r.Offset(0, 1).Value = "" Then
r.Offset(0, 1).Value = Date
End If
Next r
Application.EnableEvents = True
End Sub
Thank you for your time and consideration.
excel vba
New contributor
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I would like to preface my question with the fact that I am not a programmer, I know very little to nothing about coding and this may be very easy.
I am a mortgage loan officer and am trying to streamline my application roster. I have a Macro that I got from this life saving site but I would like to understand how I can add some utility. I have columns at the end of my table for "Reviewed," "Sold," and "dead." I have a conditional formatting set when a "y" is added to any of the columns it auto-fills that row with a corresponding color.
When I add that "y," I would also like the following column to add the date the "y" was added.
Right now I am using the following sub to auto-populate the date after the name. How can I amend it to also add the date column P if I add a y to column O, date to column R if I add a "y" to column Q and a date to column T if I add a "y" to column S.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range, B As Range, Inte As Range, r As Range
Set A = Range("A:A")
Set Inte = Intersect(A, Target)
If Inte Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each r In Inte
If r.Offset(0, 1).Value = "" Then
r.Offset(0, 1).Value = Date
End If
Next r
Application.EnableEvents = True
End Sub
Thank you for your time and consideration.
excel vba
New contributor
I would like to preface my question with the fact that I am not a programmer, I know very little to nothing about coding and this may be very easy.
I am a mortgage loan officer and am trying to streamline my application roster. I have a Macro that I got from this life saving site but I would like to understand how I can add some utility. I have columns at the end of my table for "Reviewed," "Sold," and "dead." I have a conditional formatting set when a "y" is added to any of the columns it auto-fills that row with a corresponding color.
When I add that "y," I would also like the following column to add the date the "y" was added.
Right now I am using the following sub to auto-populate the date after the name. How can I amend it to also add the date column P if I add a y to column O, date to column R if I add a "y" to column Q and a date to column T if I add a "y" to column S.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range, B As Range, Inte As Range, r As Range
Set A = Range("A:A")
Set Inte = Intersect(A, Target)
If Inte Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each r In Inte
If r.Offset(0, 1).Value = "" Then
r.Offset(0, 1).Value = Date
End If
Next r
Application.EnableEvents = True
End Sub
Thank you for your time and consideration.
excel vba
excel vba
New contributor
New contributor
edited Nov 8 at 14:16
urdearboy
5,1172625
5,1172625
New contributor
asked Nov 8 at 14:13
Jake Naman
1
1
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
You can use the Column Index
nicely here check if the Target
is in one of your key columns.
The indexes are A=1
, O=15
, Q=17
, & S=19
. Since you always want to insert the date to right, your Offset(0, 1)
will work for all cases. The last step is to just check if the cell that was changed is y
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyCell As Range
For Each MyCell In Target
Select Case Target.Column
Case 1, 15, 17, 19
Application.EnableEvents = False
If Target = "y" Then Target.Offset(, 1) = Date
Application.EnableEvents = True
End Select
Next MyCell
End Sub
add a comment |
up vote
-2
down vote
I'm not sure what the rest of your code is supposed to be doing, so here's the relevant part to what you're trying to do. The Target
variable that is being passed to the function is the cell that changed. This is set for you already.
Next you have to see what column was edited by checking Target.column
if it's in columns 15, 17, or 19 (O, Q, or S), then you know you're in the correct column. Next, you need to check if what you just entered is a 'y'. This example presumes that you're only using lowercase ys.
Finally, you can add 1 to the Target
column and set that value equal to the date.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 15 Or Target.Column = 17 Or Target.Column = 19 Then
If Target.Value = "y" Then
Cells(Target.Row, Target.Column + 1) = Date
End If
End If
End Sub
This will crash excel since you did not toggle off events
– urdearboy
Nov 8 at 14:31
Does not appear to be crashing my excel while I test it.
– Brian Cohan
Nov 8 at 14:33
Sorry, you are right. What is actually happening is your macro runs again when you use your lineCells(Target.Row, Target.Column +1) = Date
since it changes a cell. Your macro then recognizes that the changed cell is not one of the key columns. Either way, you should toggle off events to stop the macro from unnecessarily being called multiple times.
– urdearboy
Nov 8 at 14:36
Every time a target column is changed, your macro will run two times. The first will make the change, and the second will not.
– urdearboy
Nov 8 at 14:37
You are correct that it fire twice, and thanks for the reminder about the ability to disable events. But the example does not run away and crash anything. The second iteration is not going to slow down the user's computer. You could make an argument about the effect on a large sheet, but the macro is not looping over a large range.
– Brian Cohan
Nov 8 at 14:43
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
You can use the Column Index
nicely here check if the Target
is in one of your key columns.
The indexes are A=1
, O=15
, Q=17
, & S=19
. Since you always want to insert the date to right, your Offset(0, 1)
will work for all cases. The last step is to just check if the cell that was changed is y
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyCell As Range
For Each MyCell In Target
Select Case Target.Column
Case 1, 15, 17, 19
Application.EnableEvents = False
If Target = "y" Then Target.Offset(, 1) = Date
Application.EnableEvents = True
End Select
Next MyCell
End Sub
add a comment |
up vote
2
down vote
You can use the Column Index
nicely here check if the Target
is in one of your key columns.
The indexes are A=1
, O=15
, Q=17
, & S=19
. Since you always want to insert the date to right, your Offset(0, 1)
will work for all cases. The last step is to just check if the cell that was changed is y
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyCell As Range
For Each MyCell In Target
Select Case Target.Column
Case 1, 15, 17, 19
Application.EnableEvents = False
If Target = "y" Then Target.Offset(, 1) = Date
Application.EnableEvents = True
End Select
Next MyCell
End Sub
add a comment |
up vote
2
down vote
up vote
2
down vote
You can use the Column Index
nicely here check if the Target
is in one of your key columns.
The indexes are A=1
, O=15
, Q=17
, & S=19
. Since you always want to insert the date to right, your Offset(0, 1)
will work for all cases. The last step is to just check if the cell that was changed is y
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyCell As Range
For Each MyCell In Target
Select Case Target.Column
Case 1, 15, 17, 19
Application.EnableEvents = False
If Target = "y" Then Target.Offset(, 1) = Date
Application.EnableEvents = True
End Select
Next MyCell
End Sub
You can use the Column Index
nicely here check if the Target
is in one of your key columns.
The indexes are A=1
, O=15
, Q=17
, & S=19
. Since you always want to insert the date to right, your Offset(0, 1)
will work for all cases. The last step is to just check if the cell that was changed is y
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyCell As Range
For Each MyCell In Target
Select Case Target.Column
Case 1, 15, 17, 19
Application.EnableEvents = False
If Target = "y" Then Target.Offset(, 1) = Date
Application.EnableEvents = True
End Select
Next MyCell
End Sub
answered Nov 8 at 14:26
urdearboy
5,1172625
5,1172625
add a comment |
add a comment |
up vote
-2
down vote
I'm not sure what the rest of your code is supposed to be doing, so here's the relevant part to what you're trying to do. The Target
variable that is being passed to the function is the cell that changed. This is set for you already.
Next you have to see what column was edited by checking Target.column
if it's in columns 15, 17, or 19 (O, Q, or S), then you know you're in the correct column. Next, you need to check if what you just entered is a 'y'. This example presumes that you're only using lowercase ys.
Finally, you can add 1 to the Target
column and set that value equal to the date.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 15 Or Target.Column = 17 Or Target.Column = 19 Then
If Target.Value = "y" Then
Cells(Target.Row, Target.Column + 1) = Date
End If
End If
End Sub
This will crash excel since you did not toggle off events
– urdearboy
Nov 8 at 14:31
Does not appear to be crashing my excel while I test it.
– Brian Cohan
Nov 8 at 14:33
Sorry, you are right. What is actually happening is your macro runs again when you use your lineCells(Target.Row, Target.Column +1) = Date
since it changes a cell. Your macro then recognizes that the changed cell is not one of the key columns. Either way, you should toggle off events to stop the macro from unnecessarily being called multiple times.
– urdearboy
Nov 8 at 14:36
Every time a target column is changed, your macro will run two times. The first will make the change, and the second will not.
– urdearboy
Nov 8 at 14:37
You are correct that it fire twice, and thanks for the reminder about the ability to disable events. But the example does not run away and crash anything. The second iteration is not going to slow down the user's computer. You could make an argument about the effect on a large sheet, but the macro is not looping over a large range.
– Brian Cohan
Nov 8 at 14:43
add a comment |
up vote
-2
down vote
I'm not sure what the rest of your code is supposed to be doing, so here's the relevant part to what you're trying to do. The Target
variable that is being passed to the function is the cell that changed. This is set for you already.
Next you have to see what column was edited by checking Target.column
if it's in columns 15, 17, or 19 (O, Q, or S), then you know you're in the correct column. Next, you need to check if what you just entered is a 'y'. This example presumes that you're only using lowercase ys.
Finally, you can add 1 to the Target
column and set that value equal to the date.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 15 Or Target.Column = 17 Or Target.Column = 19 Then
If Target.Value = "y" Then
Cells(Target.Row, Target.Column + 1) = Date
End If
End If
End Sub
This will crash excel since you did not toggle off events
– urdearboy
Nov 8 at 14:31
Does not appear to be crashing my excel while I test it.
– Brian Cohan
Nov 8 at 14:33
Sorry, you are right. What is actually happening is your macro runs again when you use your lineCells(Target.Row, Target.Column +1) = Date
since it changes a cell. Your macro then recognizes that the changed cell is not one of the key columns. Either way, you should toggle off events to stop the macro from unnecessarily being called multiple times.
– urdearboy
Nov 8 at 14:36
Every time a target column is changed, your macro will run two times. The first will make the change, and the second will not.
– urdearboy
Nov 8 at 14:37
You are correct that it fire twice, and thanks for the reminder about the ability to disable events. But the example does not run away and crash anything. The second iteration is not going to slow down the user's computer. You could make an argument about the effect on a large sheet, but the macro is not looping over a large range.
– Brian Cohan
Nov 8 at 14:43
add a comment |
up vote
-2
down vote
up vote
-2
down vote
I'm not sure what the rest of your code is supposed to be doing, so here's the relevant part to what you're trying to do. The Target
variable that is being passed to the function is the cell that changed. This is set for you already.
Next you have to see what column was edited by checking Target.column
if it's in columns 15, 17, or 19 (O, Q, or S), then you know you're in the correct column. Next, you need to check if what you just entered is a 'y'. This example presumes that you're only using lowercase ys.
Finally, you can add 1 to the Target
column and set that value equal to the date.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 15 Or Target.Column = 17 Or Target.Column = 19 Then
If Target.Value = "y" Then
Cells(Target.Row, Target.Column + 1) = Date
End If
End If
End Sub
I'm not sure what the rest of your code is supposed to be doing, so here's the relevant part to what you're trying to do. The Target
variable that is being passed to the function is the cell that changed. This is set for you already.
Next you have to see what column was edited by checking Target.column
if it's in columns 15, 17, or 19 (O, Q, or S), then you know you're in the correct column. Next, you need to check if what you just entered is a 'y'. This example presumes that you're only using lowercase ys.
Finally, you can add 1 to the Target
column and set that value equal to the date.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 15 Or Target.Column = 17 Or Target.Column = 19 Then
If Target.Value = "y" Then
Cells(Target.Row, Target.Column + 1) = Date
End If
End If
End Sub
answered Nov 8 at 14:22
Brian Cohan
1,8411821
1,8411821
This will crash excel since you did not toggle off events
– urdearboy
Nov 8 at 14:31
Does not appear to be crashing my excel while I test it.
– Brian Cohan
Nov 8 at 14:33
Sorry, you are right. What is actually happening is your macro runs again when you use your lineCells(Target.Row, Target.Column +1) = Date
since it changes a cell. Your macro then recognizes that the changed cell is not one of the key columns. Either way, you should toggle off events to stop the macro from unnecessarily being called multiple times.
– urdearboy
Nov 8 at 14:36
Every time a target column is changed, your macro will run two times. The first will make the change, and the second will not.
– urdearboy
Nov 8 at 14:37
You are correct that it fire twice, and thanks for the reminder about the ability to disable events. But the example does not run away and crash anything. The second iteration is not going to slow down the user's computer. You could make an argument about the effect on a large sheet, but the macro is not looping over a large range.
– Brian Cohan
Nov 8 at 14:43
add a comment |
This will crash excel since you did not toggle off events
– urdearboy
Nov 8 at 14:31
Does not appear to be crashing my excel while I test it.
– Brian Cohan
Nov 8 at 14:33
Sorry, you are right. What is actually happening is your macro runs again when you use your lineCells(Target.Row, Target.Column +1) = Date
since it changes a cell. Your macro then recognizes that the changed cell is not one of the key columns. Either way, you should toggle off events to stop the macro from unnecessarily being called multiple times.
– urdearboy
Nov 8 at 14:36
Every time a target column is changed, your macro will run two times. The first will make the change, and the second will not.
– urdearboy
Nov 8 at 14:37
You are correct that it fire twice, and thanks for the reminder about the ability to disable events. But the example does not run away and crash anything. The second iteration is not going to slow down the user's computer. You could make an argument about the effect on a large sheet, but the macro is not looping over a large range.
– Brian Cohan
Nov 8 at 14:43
This will crash excel since you did not toggle off events
– urdearboy
Nov 8 at 14:31
This will crash excel since you did not toggle off events
– urdearboy
Nov 8 at 14:31
Does not appear to be crashing my excel while I test it.
– Brian Cohan
Nov 8 at 14:33
Does not appear to be crashing my excel while I test it.
– Brian Cohan
Nov 8 at 14:33
Sorry, you are right. What is actually happening is your macro runs again when you use your line
Cells(Target.Row, Target.Column +1) = Date
since it changes a cell. Your macro then recognizes that the changed cell is not one of the key columns. Either way, you should toggle off events to stop the macro from unnecessarily being called multiple times.– urdearboy
Nov 8 at 14:36
Sorry, you are right. What is actually happening is your macro runs again when you use your line
Cells(Target.Row, Target.Column +1) = Date
since it changes a cell. Your macro then recognizes that the changed cell is not one of the key columns. Either way, you should toggle off events to stop the macro from unnecessarily being called multiple times.– urdearboy
Nov 8 at 14:36
Every time a target column is changed, your macro will run two times. The first will make the change, and the second will not.
– urdearboy
Nov 8 at 14:37
Every time a target column is changed, your macro will run two times. The first will make the change, and the second will not.
– urdearboy
Nov 8 at 14:37
You are correct that it fire twice, and thanks for the reminder about the ability to disable events. But the example does not run away and crash anything. The second iteration is not going to slow down the user's computer. You could make an argument about the effect on a large sheet, but the macro is not looping over a large range.
– Brian Cohan
Nov 8 at 14:43
You are correct that it fire twice, and thanks for the reminder about the ability to disable events. But the example does not run away and crash anything. The second iteration is not going to slow down the user's computer. You could make an argument about the effect on a large sheet, but the macro is not looping over a large range.
– Brian Cohan
Nov 8 at 14:43
add a comment |
Jake Naman is a new contributor. Be nice, and check out our Code of Conduct.
Jake Naman is a new contributor. Be nice, and check out our Code of Conduct.
Jake Naman is a new contributor. Be nice, and check out our Code of Conduct.
Jake Naman is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53209530%2fvba-macro-auto-filling-date-in-following-column-once-a-value-is-added-independ%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password