Assigning a VBA to a specific column.

JEH105

New Member
Joined
Oct 11, 2019
Messages
2
Hi everyone,

I'm not very experienced in VBA, but I found the following code in order to add time stamps to a workbook. However, I need the timestamps to be added to column D only. Currently, it applies the timestamps to ALL cells. Here is the code:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

With Target

If Not IsEmpty(.Value) Then

' Jack Clears the comment.

.ClearComments

' Jack Creates the comment.

.AddComment (Application.UserName & " ; " & Date & " ;" & Time)

' Can have user name in top left by adding name between ""

.Comment.Visible = False



Else: .ClearComments

End If

End With



End Sub

I appreciate any help you can provide! :)
 

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,691
Office Version
  1. 2010
Platform
  1. Windows
Give this Change event code a try...
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Cell As Range
  On Error GoTo NothingInColumnD
  For Each Cell In Intersect(Target, Columns("D"))
    With Cell
      If .Column = 4 Then
        .ClearComments
        If Len(.Value) Then
          .AddComment Application.UserName & " ; " & Date & " ;" & Time
          .Comment.Visible = False
        End If
      End If
    End With
  Next
NothingInColumnD:
End Sub
 

JEH105

New Member
Joined
Oct 11, 2019
Messages
2
Thank you so much! This is exactly what I needed. I appreciate your help at this time! :)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,832
Messages
5,598,363
Members
414,233
Latest member
WolverineNurse

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
Top