简体   繁体   中英

Excel VBA write to active cell

This should be so simple. All I want is for when a user clicks in a cell, say any cell in column B, then a concatenation of ...

text string "Update: " Date/time Their userID (Application.UserName)

I know I need something like:

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Selection.Count = 1 Then
        If Not Intersect(Target, Range("D4")) Is Nothing Then
            ActiveCell.Select Environ("UserName")
        End If
    End If
End Sub

... gets written to that cell. Eg Update: Jane Smith 1/1/2015 00:00

Hope someone can help :-) Thanks

For any cell in column B, it would be:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Selection.Count = 1 Then
        If Not Intersect(Target, Range("B:B")) Is Nothing Then
           Target.Value = Target.Value & " Update: " & Environ("username") & " " & Now
        End If
    End If
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM