VBA code needed to clear contents of cell AQ when value of cell D changes; Microsoft Excel for Office 365 MSO...











up vote
0
down vote

favorite












I'll preface this by saying that programming is not my strong suit but I would appreciate any help.



I have used the below formula in an attempt to clear the contents of cell AQ when the value of cell D (on the same row) changes. Currently, the contents are only cleared in AQ when the value in cell D changes to 1 (presumably due to the line "If Target = 1 Then". What do I use instead of "1" so that all changes, from any value to any value, will initiate the ClearContents instruction for cell AQ?



Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
If Target = 1 Then
Range("AQ" & Target.Row).ClearContents
End If
End If
End Sub









share|improve this question






















  • Why are you testing If Target = 1?  Why not just take it out and do If Not Intersect(Target, Range("D7:D506")) Is Nothing Then ... Range("AQ" & Target.Row).ClearContents?
    – Scott
    Nov 20 at 2:53










  • Hi Scott, I just figured this out. I should've looked at your response an hour ago! To answer your question: that's the problem when one plagiarises all one's code from other similar examples on the web. Simple solutions are not obvious to the uninitiated. While I have you, is there code i could add that would prevent AQ from clearing if the value of D is changed to the same value. (i.e. D=1, then i input D=1 again). Currently the code can't differentiate between a true change in value (i.e. 1 to 2) and just a re-entering of the same value (i.e. 1 to 1).
    – MJS
    Nov 20 at 4:09












  • Interesting question. I have fairly little experience with Worksheet_Change. I assume that you’ve verified through experimentation that the Worksheet_Change routine gets called even when a cell is “changed” to its current value? In that case, I suspect that you’re out of luck (anybody who knows better, feel free to correct me!). The one thing I can suggest is that you keep a backup copy of Column D, and compare the “new” value to your saved copy.
    – Scott
    Nov 20 at 4:17










  • Thanks for the help @Scott
    – MJS
    Nov 20 at 23:15










  • Thank you @Christofer Weber. I had some issues with your code but I received a (seemingly) workable solution on another forum in the meantime so hopefully won't need this now. But thank you for your time and effort.
    – MJS
    Nov 21 at 10:47















up vote
0
down vote

favorite












I'll preface this by saying that programming is not my strong suit but I would appreciate any help.



I have used the below formula in an attempt to clear the contents of cell AQ when the value of cell D (on the same row) changes. Currently, the contents are only cleared in AQ when the value in cell D changes to 1 (presumably due to the line "If Target = 1 Then". What do I use instead of "1" so that all changes, from any value to any value, will initiate the ClearContents instruction for cell AQ?



Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
If Target = 1 Then
Range("AQ" & Target.Row).ClearContents
End If
End If
End Sub









share|improve this question






















  • Why are you testing If Target = 1?  Why not just take it out and do If Not Intersect(Target, Range("D7:D506")) Is Nothing Then ... Range("AQ" & Target.Row).ClearContents?
    – Scott
    Nov 20 at 2:53










  • Hi Scott, I just figured this out. I should've looked at your response an hour ago! To answer your question: that's the problem when one plagiarises all one's code from other similar examples on the web. Simple solutions are not obvious to the uninitiated. While I have you, is there code i could add that would prevent AQ from clearing if the value of D is changed to the same value. (i.e. D=1, then i input D=1 again). Currently the code can't differentiate between a true change in value (i.e. 1 to 2) and just a re-entering of the same value (i.e. 1 to 1).
    – MJS
    Nov 20 at 4:09












  • Interesting question. I have fairly little experience with Worksheet_Change. I assume that you’ve verified through experimentation that the Worksheet_Change routine gets called even when a cell is “changed” to its current value? In that case, I suspect that you’re out of luck (anybody who knows better, feel free to correct me!). The one thing I can suggest is that you keep a backup copy of Column D, and compare the “new” value to your saved copy.
    – Scott
    Nov 20 at 4:17










  • Thanks for the help @Scott
    – MJS
    Nov 20 at 23:15










  • Thank you @Christofer Weber. I had some issues with your code but I received a (seemingly) workable solution on another forum in the meantime so hopefully won't need this now. But thank you for your time and effort.
    – MJS
    Nov 21 at 10:47













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'll preface this by saying that programming is not my strong suit but I would appreciate any help.



I have used the below formula in an attempt to clear the contents of cell AQ when the value of cell D (on the same row) changes. Currently, the contents are only cleared in AQ when the value in cell D changes to 1 (presumably due to the line "If Target = 1 Then". What do I use instead of "1" so that all changes, from any value to any value, will initiate the ClearContents instruction for cell AQ?



Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
If Target = 1 Then
Range("AQ" & Target.Row).ClearContents
End If
End If
End Sub









share|improve this question













I'll preface this by saying that programming is not my strong suit but I would appreciate any help.



I have used the below formula in an attempt to clear the contents of cell AQ when the value of cell D (on the same row) changes. Currently, the contents are only cleared in AQ when the value in cell D changes to 1 (presumably due to the line "If Target = 1 Then". What do I use instead of "1" so that all changes, from any value to any value, will initiate the ClearContents instruction for cell AQ?



Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
If Target = 1 Then
Range("AQ" & Target.Row).ClearContents
End If
End If
End Sub






microsoft-excel vba microsoft-excel-2016






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 1:45









MJS

11




11












  • Why are you testing If Target = 1?  Why not just take it out and do If Not Intersect(Target, Range("D7:D506")) Is Nothing Then ... Range("AQ" & Target.Row).ClearContents?
    – Scott
    Nov 20 at 2:53










  • Hi Scott, I just figured this out. I should've looked at your response an hour ago! To answer your question: that's the problem when one plagiarises all one's code from other similar examples on the web. Simple solutions are not obvious to the uninitiated. While I have you, is there code i could add that would prevent AQ from clearing if the value of D is changed to the same value. (i.e. D=1, then i input D=1 again). Currently the code can't differentiate between a true change in value (i.e. 1 to 2) and just a re-entering of the same value (i.e. 1 to 1).
    – MJS
    Nov 20 at 4:09












  • Interesting question. I have fairly little experience with Worksheet_Change. I assume that you’ve verified through experimentation that the Worksheet_Change routine gets called even when a cell is “changed” to its current value? In that case, I suspect that you’re out of luck (anybody who knows better, feel free to correct me!). The one thing I can suggest is that you keep a backup copy of Column D, and compare the “new” value to your saved copy.
    – Scott
    Nov 20 at 4:17










  • Thanks for the help @Scott
    – MJS
    Nov 20 at 23:15










  • Thank you @Christofer Weber. I had some issues with your code but I received a (seemingly) workable solution on another forum in the meantime so hopefully won't need this now. But thank you for your time and effort.
    – MJS
    Nov 21 at 10:47


















  • Why are you testing If Target = 1?  Why not just take it out and do If Not Intersect(Target, Range("D7:D506")) Is Nothing Then ... Range("AQ" & Target.Row).ClearContents?
    – Scott
    Nov 20 at 2:53










  • Hi Scott, I just figured this out. I should've looked at your response an hour ago! To answer your question: that's the problem when one plagiarises all one's code from other similar examples on the web. Simple solutions are not obvious to the uninitiated. While I have you, is there code i could add that would prevent AQ from clearing if the value of D is changed to the same value. (i.e. D=1, then i input D=1 again). Currently the code can't differentiate between a true change in value (i.e. 1 to 2) and just a re-entering of the same value (i.e. 1 to 1).
    – MJS
    Nov 20 at 4:09












  • Interesting question. I have fairly little experience with Worksheet_Change. I assume that you’ve verified through experimentation that the Worksheet_Change routine gets called even when a cell is “changed” to its current value? In that case, I suspect that you’re out of luck (anybody who knows better, feel free to correct me!). The one thing I can suggest is that you keep a backup copy of Column D, and compare the “new” value to your saved copy.
    – Scott
    Nov 20 at 4:17










  • Thanks for the help @Scott
    – MJS
    Nov 20 at 23:15










  • Thank you @Christofer Weber. I had some issues with your code but I received a (seemingly) workable solution on another forum in the meantime so hopefully won't need this now. But thank you for your time and effort.
    – MJS
    Nov 21 at 10:47
















Why are you testing If Target = 1?  Why not just take it out and do If Not Intersect(Target, Range("D7:D506")) Is Nothing Then ... Range("AQ" & Target.Row).ClearContents?
– Scott
Nov 20 at 2:53




Why are you testing If Target = 1?  Why not just take it out and do If Not Intersect(Target, Range("D7:D506")) Is Nothing Then ... Range("AQ" & Target.Row).ClearContents?
– Scott
Nov 20 at 2:53












Hi Scott, I just figured this out. I should've looked at your response an hour ago! To answer your question: that's the problem when one plagiarises all one's code from other similar examples on the web. Simple solutions are not obvious to the uninitiated. While I have you, is there code i could add that would prevent AQ from clearing if the value of D is changed to the same value. (i.e. D=1, then i input D=1 again). Currently the code can't differentiate between a true change in value (i.e. 1 to 2) and just a re-entering of the same value (i.e. 1 to 1).
– MJS
Nov 20 at 4:09






Hi Scott, I just figured this out. I should've looked at your response an hour ago! To answer your question: that's the problem when one plagiarises all one's code from other similar examples on the web. Simple solutions are not obvious to the uninitiated. While I have you, is there code i could add that would prevent AQ from clearing if the value of D is changed to the same value. (i.e. D=1, then i input D=1 again). Currently the code can't differentiate between a true change in value (i.e. 1 to 2) and just a re-entering of the same value (i.e. 1 to 1).
– MJS
Nov 20 at 4:09














Interesting question. I have fairly little experience with Worksheet_Change. I assume that you’ve verified through experimentation that the Worksheet_Change routine gets called even when a cell is “changed” to its current value? In that case, I suspect that you’re out of luck (anybody who knows better, feel free to correct me!). The one thing I can suggest is that you keep a backup copy of Column D, and compare the “new” value to your saved copy.
– Scott
Nov 20 at 4:17




Interesting question. I have fairly little experience with Worksheet_Change. I assume that you’ve verified through experimentation that the Worksheet_Change routine gets called even when a cell is “changed” to its current value? In that case, I suspect that you’re out of luck (anybody who knows better, feel free to correct me!). The one thing I can suggest is that you keep a backup copy of Column D, and compare the “new” value to your saved copy.
– Scott
Nov 20 at 4:17












Thanks for the help @Scott
– MJS
Nov 20 at 23:15




Thanks for the help @Scott
– MJS
Nov 20 at 23:15












Thank you @Christofer Weber. I had some issues with your code but I received a (seemingly) workable solution on another forum in the meantime so hopefully won't need this now. But thank you for your time and effort.
– MJS
Nov 21 at 10:47




Thank you @Christofer Weber. I had some issues with your code but I received a (seemingly) workable solution on another forum in the meantime so hopefully won't need this now. But thank you for your time and effort.
– MJS
Nov 21 at 10:47










1 Answer
1






active

oldest

votes

















up vote
0
down vote













To make sure a true change has occurred, we first save the value of the selected cell as a public variable. Since you can select more than one cell at once, I've decided to use a public Collection.



Then when a change occurs we compare the new value of that cell to the old value in the collection, and only if they don't match, clear the contents of AQ.
Something like:



Public coll As New Collection

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cel As Range
Set coll = New Collection
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
For Each cel In Target
coll.Add cel.Value, cel.Address
Next cel
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
If Not Target.Value = coll(Target.Address) Then
Range("AQ" & Target.Row).ClearContents
End If
End If
End Sub


Edit updated to work when selecting multiple cells.



Obviously, if you change a value in Range("D7:D506") without actually selecting the cell first, this code will throw an error.



Come to think of it, you can edit multiple cells at once, if you delete the value. Then this code will also throw an error.
But we can work around that by using the same approach in Worksheet_Change as we are doing in Worksheet_SelectionChange:



Private Sub Worksheet_Change(ByVal Target As Range)
Dim cel As Range
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
For Each cel In Target
If Not cel.Value = coll(cel.Address) Then
Range("AQ" & cel.Row).ClearContents
End If
Next cel
End If
End Sub





share|improve this answer



















  • 1




    (1) Nice. I was thinking in terms of keeping a copy of Column D somewhere else on the worksheet (e.g., Column AD); keeping it in VBA memory seems safer. (2) Between the question title and the If Not Intersect(Target, Range("D7:D506")) Is Nothing Then line, it appears that the user is concerned only with changes in Column D; specifically, in the range D7:D506.  So I would suggest that your routine should do, not For Each cel In Target, but rather For Each cel In Intersect(Target, Range("D7:D506")).
    – Scott
    Nov 26 at 22:24










  • Putting the intersect in the for loop condition? Never thought of that. I like it! Very efficient.
    – Christofer Weber
    2 days ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1376833%2fvba-code-needed-to-clear-contents-of-cell-aq-when-value-of-cell-d-changes-micro%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













To make sure a true change has occurred, we first save the value of the selected cell as a public variable. Since you can select more than one cell at once, I've decided to use a public Collection.



Then when a change occurs we compare the new value of that cell to the old value in the collection, and only if they don't match, clear the contents of AQ.
Something like:



Public coll As New Collection

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cel As Range
Set coll = New Collection
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
For Each cel In Target
coll.Add cel.Value, cel.Address
Next cel
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
If Not Target.Value = coll(Target.Address) Then
Range("AQ" & Target.Row).ClearContents
End If
End If
End Sub


Edit updated to work when selecting multiple cells.



Obviously, if you change a value in Range("D7:D506") without actually selecting the cell first, this code will throw an error.



Come to think of it, you can edit multiple cells at once, if you delete the value. Then this code will also throw an error.
But we can work around that by using the same approach in Worksheet_Change as we are doing in Worksheet_SelectionChange:



Private Sub Worksheet_Change(ByVal Target As Range)
Dim cel As Range
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
For Each cel In Target
If Not cel.Value = coll(cel.Address) Then
Range("AQ" & cel.Row).ClearContents
End If
Next cel
End If
End Sub





share|improve this answer



















  • 1




    (1) Nice. I was thinking in terms of keeping a copy of Column D somewhere else on the worksheet (e.g., Column AD); keeping it in VBA memory seems safer. (2) Between the question title and the If Not Intersect(Target, Range("D7:D506")) Is Nothing Then line, it appears that the user is concerned only with changes in Column D; specifically, in the range D7:D506.  So I would suggest that your routine should do, not For Each cel In Target, but rather For Each cel In Intersect(Target, Range("D7:D506")).
    – Scott
    Nov 26 at 22:24










  • Putting the intersect in the for loop condition? Never thought of that. I like it! Very efficient.
    – Christofer Weber
    2 days ago















up vote
0
down vote













To make sure a true change has occurred, we first save the value of the selected cell as a public variable. Since you can select more than one cell at once, I've decided to use a public Collection.



Then when a change occurs we compare the new value of that cell to the old value in the collection, and only if they don't match, clear the contents of AQ.
Something like:



Public coll As New Collection

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cel As Range
Set coll = New Collection
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
For Each cel In Target
coll.Add cel.Value, cel.Address
Next cel
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
If Not Target.Value = coll(Target.Address) Then
Range("AQ" & Target.Row).ClearContents
End If
End If
End Sub


Edit updated to work when selecting multiple cells.



Obviously, if you change a value in Range("D7:D506") without actually selecting the cell first, this code will throw an error.



Come to think of it, you can edit multiple cells at once, if you delete the value. Then this code will also throw an error.
But we can work around that by using the same approach in Worksheet_Change as we are doing in Worksheet_SelectionChange:



Private Sub Worksheet_Change(ByVal Target As Range)
Dim cel As Range
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
For Each cel In Target
If Not cel.Value = coll(cel.Address) Then
Range("AQ" & cel.Row).ClearContents
End If
Next cel
End If
End Sub





share|improve this answer



















  • 1




    (1) Nice. I was thinking in terms of keeping a copy of Column D somewhere else on the worksheet (e.g., Column AD); keeping it in VBA memory seems safer. (2) Between the question title and the If Not Intersect(Target, Range("D7:D506")) Is Nothing Then line, it appears that the user is concerned only with changes in Column D; specifically, in the range D7:D506.  So I would suggest that your routine should do, not For Each cel In Target, but rather For Each cel In Intersect(Target, Range("D7:D506")).
    – Scott
    Nov 26 at 22:24










  • Putting the intersect in the for loop condition? Never thought of that. I like it! Very efficient.
    – Christofer Weber
    2 days ago













up vote
0
down vote










up vote
0
down vote









To make sure a true change has occurred, we first save the value of the selected cell as a public variable. Since you can select more than one cell at once, I've decided to use a public Collection.



Then when a change occurs we compare the new value of that cell to the old value in the collection, and only if they don't match, clear the contents of AQ.
Something like:



Public coll As New Collection

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cel As Range
Set coll = New Collection
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
For Each cel In Target
coll.Add cel.Value, cel.Address
Next cel
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
If Not Target.Value = coll(Target.Address) Then
Range("AQ" & Target.Row).ClearContents
End If
End If
End Sub


Edit updated to work when selecting multiple cells.



Obviously, if you change a value in Range("D7:D506") without actually selecting the cell first, this code will throw an error.



Come to think of it, you can edit multiple cells at once, if you delete the value. Then this code will also throw an error.
But we can work around that by using the same approach in Worksheet_Change as we are doing in Worksheet_SelectionChange:



Private Sub Worksheet_Change(ByVal Target As Range)
Dim cel As Range
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
For Each cel In Target
If Not cel.Value = coll(cel.Address) Then
Range("AQ" & cel.Row).ClearContents
End If
Next cel
End If
End Sub





share|improve this answer














To make sure a true change has occurred, we first save the value of the selected cell as a public variable. Since you can select more than one cell at once, I've decided to use a public Collection.



Then when a change occurs we compare the new value of that cell to the old value in the collection, and only if they don't match, clear the contents of AQ.
Something like:



Public coll As New Collection

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cel As Range
Set coll = New Collection
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
For Each cel In Target
coll.Add cel.Value, cel.Address
Next cel
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
If Not Target.Value = coll(Target.Address) Then
Range("AQ" & Target.Row).ClearContents
End If
End If
End Sub


Edit updated to work when selecting multiple cells.



Obviously, if you change a value in Range("D7:D506") without actually selecting the cell first, this code will throw an error.



Come to think of it, you can edit multiple cells at once, if you delete the value. Then this code will also throw an error.
But we can work around that by using the same approach in Worksheet_Change as we are doing in Worksheet_SelectionChange:



Private Sub Worksheet_Change(ByVal Target As Range)
Dim cel As Range
If Not Intersect(Target, Range("D7:D506")) Is Nothing Then
For Each cel In Target
If Not cel.Value = coll(cel.Address) Then
Range("AQ" & cel.Row).ClearContents
End If
Next cel
End If
End Sub






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 at 18:43

























answered Nov 20 at 15:35









Christofer Weber

709413




709413








  • 1




    (1) Nice. I was thinking in terms of keeping a copy of Column D somewhere else on the worksheet (e.g., Column AD); keeping it in VBA memory seems safer. (2) Between the question title and the If Not Intersect(Target, Range("D7:D506")) Is Nothing Then line, it appears that the user is concerned only with changes in Column D; specifically, in the range D7:D506.  So I would suggest that your routine should do, not For Each cel In Target, but rather For Each cel In Intersect(Target, Range("D7:D506")).
    – Scott
    Nov 26 at 22:24










  • Putting the intersect in the for loop condition? Never thought of that. I like it! Very efficient.
    – Christofer Weber
    2 days ago














  • 1




    (1) Nice. I was thinking in terms of keeping a copy of Column D somewhere else on the worksheet (e.g., Column AD); keeping it in VBA memory seems safer. (2) Between the question title and the If Not Intersect(Target, Range("D7:D506")) Is Nothing Then line, it appears that the user is concerned only with changes in Column D; specifically, in the range D7:D506.  So I would suggest that your routine should do, not For Each cel In Target, but rather For Each cel In Intersect(Target, Range("D7:D506")).
    – Scott
    Nov 26 at 22:24










  • Putting the intersect in the for loop condition? Never thought of that. I like it! Very efficient.
    – Christofer Weber
    2 days ago








1




1




(1) Nice. I was thinking in terms of keeping a copy of Column D somewhere else on the worksheet (e.g., Column AD); keeping it in VBA memory seems safer. (2) Between the question title and the If Not Intersect(Target, Range("D7:D506")) Is Nothing Then line, it appears that the user is concerned only with changes in Column D; specifically, in the range D7:D506.  So I would suggest that your routine should do, not For Each cel In Target, but rather For Each cel In Intersect(Target, Range("D7:D506")).
– Scott
Nov 26 at 22:24




(1) Nice. I was thinking in terms of keeping a copy of Column D somewhere else on the worksheet (e.g., Column AD); keeping it in VBA memory seems safer. (2) Between the question title and the If Not Intersect(Target, Range("D7:D506")) Is Nothing Then line, it appears that the user is concerned only with changes in Column D; specifically, in the range D7:D506.  So I would suggest that your routine should do, not For Each cel In Target, but rather For Each cel In Intersect(Target, Range("D7:D506")).
– Scott
Nov 26 at 22:24












Putting the intersect in the for loop condition? Never thought of that. I like it! Very efficient.
– Christofer Weber
2 days ago




Putting the intersect in the for loop condition? Never thought of that. I like it! Very efficient.
– Christofer Weber
2 days ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1376833%2fvba-code-needed-to-clear-contents-of-cell-aq-when-value-of-cell-d-changes-micro%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

QoS: MAC-Priority for clients behind a repeater

Ивакино (Тотемский район)

Can't locate Autom4te/ChannelDefs.pm in @INC (when it definitely is there)