2017-03-08 74 views

回答

0

这是一个宏,会做同样的事情,作为一个公式:

在您的工作表的代码

Private Sub Worksheet_Change(ByVal Target As Range) 

If Target.Address = "$F$4" Then 'assuming the name you are searching is in F4 
    Dim i As Integer 
    Dim check As Integer 

    Dim LastRow As Long 
    With ActiveSheet 
     LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 
    End With 

    For i = 2 To LastRow 
     If Cells(i, 1).Value = Target.Value Then 
      Cells(i, 1).Offset(0, 1).Value = 1 
      check = 1 
     End If 
    Next i 

    If check > 0 Then 
     Exit Sub 
    Else 
     LastRow = LastRow + 1 
     Cells(LastRow, 1).Value = Target.Value 
    End If 
End If 
End Sub 
+0

嗨将这个,感谢您的代码,但是有一个问题如果再次输入用户名,我希望它添加1,这只会上升到1 :( – user7531258

+1

谢谢你的代码,我通过这样做Cells(i,1).Offset(0,1)解决了问题。值= Cells(i,1).Offset(0,1).Value + 1再次感谢! – user7531258

相关问题