Can anyone help me in vba???

jovie

Board Regular
Joined
Nov 13, 2015
Messages
68
Hi I am very new of VBA, which I would like to write a code that
when I updated one column's(like said column 1) value, the other column(column 2) will updated to current date, and other rows will not be affected if the column 1's value is not changed.
And is it possible that once I forget to update column 2's date, next time when I click the button ,it will update column 2's date to the date I update column 1's value
Thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I wouldn't bother with a button, just use a Change event.

<font face=Calibri><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)<br>    <SPAN style="color:#007F00">'   Code goes in the Worksheet specific module</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> Rng <SPAN style="color:#00007F">As</SPAN> Range<br>        <SPAN style="color:#007F00">'   Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")</SPAN><br>        <SPAN style="color:#00007F">Set</SPAN> Rng = Target.Parent.Range("A:A")<br>             <SPAN style="color:#007F00">'   Only look at single cell changes</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Target.Count > 1 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>            <SPAN style="color:#007F00">'   Only look at that range</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Intersect(Target, Rng) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>            <SPAN style="color:#007F00">'   Action if Condition(s) are met (do your thing here...)</SPAN><br>            Target.Offset(, 1).Value = <SPAN style="color:#00007F">Date</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

You'll need to change the column 1 reference (I used column A) to whatever you want.

Note that the code goes in the worksheet specific module, not a general module. Just right-click on the sheet tab and select View Code, then paste the code in the new window.

HTH,
 
Upvote 0
I forgot to mention, a Change event is completely automatic, so you don't need to worry about pressing buttons or forgetting things.
 
Upvote 0
I forgot to mention, a Change event is completely automatic, so you don't need to worry about pressing buttons or forgetting things.

I try the code ald, thanks a lot for helping, can help me one more thing, just there is two cell , cell 1 and cell 2 , when cell 1's value change, cell 2's value will automatically plus the cell 1's value, sorry to trouble, just I cant find the code online
 
Upvote 0
sorry, can I ask one more that, because my column 1 the value is change base on a formula I set up, however the code will only activate when I manually change the date on that, can make it like it will change the date of Column 2 once column 1's value is changed
 
Upvote 0
I forgot to mention, a Change event is completely automatic, so you don't need to worry about pressing buttons or forgetting things.
[h=2]
icon1.png
Re: Can anyone help me in vba???[/h]
sorry, can I ask one more that, because my column 1 the value is change base on a formula I set up, however the code will only activate when I manually change the date on that, can make it like it will change the date of Column 2 once column 1's value is changes​
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
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