Assigning a VBA to a specific column.

JEH105

New Member
Joined
Oct 11, 2019
Messages
20
Office Version
  1. 365
Platform
  1. Windows
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! :)
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,881
Office Version
  1. 2019
  2. 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
 
Solution

JEH105

New Member
Joined
Oct 11, 2019
Messages
20
Office Version
  1. 365
Platform
  1. Windows
Thank you so much! This is exactly what I needed. I appreciate your help at this time! :)
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,030
Messages
5,835,039
Members
430,334
Latest member
matolibriyum

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