如果用户在单元格中输入文本,则在另一个单元格中返回用户名和日期

问题描述 投票:-5回答:2

帮助,在共享工作表中,如果用户在单元格中添加文本,则单击按钮以在另一个单元格中返回用户名和日期。例如,单元格B3 =完成,然后单元格C3返回John Smith 14/04/19

非常感谢!

excel vba
2个回答
2
投票

不需要VBA。尝试:

=IF(B6="Complete", "User Name " & TEXT(NOW(),"dd/mm/yyyy"),"")

结果:

enter image description here


0
投票

更多信息可能会有所帮助。我将假设工作表的布局如下。你需要一些方法来指定当前用户是谁,在这个例子中我使用了单元格A2。

enter image description here

如果布局不是如图所示,则需要相应地编辑代码。

Sub date_user()

Dim lastrow As Long
Dim rng As Range, cell As Range

With Application.ActiveSheet
    Name = .Range("A2").Value
    lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    Set rng = .Range("B3:B" & lastrow)
End With

For Each cell In rng
    If cell.Offset(0, 1).Value = 0 Then
        If Len(cell.Value) > 0 Then
           cell.Offset(0, 1).Value = Name & " " & Format(Now(), "MMM-DD-YYYY")
        End If
    End If
Next     
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.