How to insert VBA code into a cell?

jayantht

New Member
Joined
Feb 27, 2013
Messages
3
I'm a complete novice to VBA and Excel. I have a piece of VBA.
I got this code from this forum.
This VBA code records the date-time when when another cell has changed.
OK, I get the code pasted into the code editor and saved the file.
The data I change (e.g. manually is in A2) B2 should automatically get updated with the date it changed
How to insert the code into this cell?
Thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
You probably need to right click the sheet tab, select View Code and paste in the code.
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'will put date in a comment when something is put in Column A created by Paul B
If Target.Column = 1 Then
Comment = ("Cell Last Edited: ") & Now & (" by ") & Application.UserName
Target.Cells.NoteText Comment
End If
End Sub

The second one I got from this forum is much simpler:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then Cells(Target.Row, 2) = Now()
End Sub



Yes, I've done the right click on the sheet tab and inserted the code in the sheet that shows up.
How do I activate this code in a particular cell?
 
Upvote 0
You enter something in column A.

You can only have one of those codes, not both, or you'll get an error.
 
Upvote 0
You are right, I tried with just one of the pieces of the code not both.
Again, I think my question is very simple, I'm entering a piece of data in cell A1. I want the cell B1 to show the date and time and many the user who changed the data in cell A1.
I believe the first piece of code does that.
the question is what should I put in cell B1, so that it the code is run.

As an example: if I want to multiply contents of A1 and B1 and put the result in C1, I'd type =A1*B1 into C1, similarly what should I put in cell B1 for capturing the change in cell A1.
Thanks
 
Upvote 0

Forum statistics

Threads
1,216,102
Messages
6,128,852
Members
449,471
Latest member
lachbee

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