一旦达到第一列中的复制值,如何自动填充行的其余部分

How to autofill rest of the row once a replicated value in the first column is reached

我有一个 excel sheet 是为客户服务定义的。如果 Customer_ID 的值在未来的服务中重复,我想使用 VB 为列 A (Customer_ID) 的相关值进行行自动填充。那么,我怎样才能在同一个 sheet 中做到这一点呢?行内容的一个例子是:

"Customer_ID"   "Identity_No."   "City"   "Customer's_Name"   "Phone_No."   "Email"

"LON9501"       "22024245423"   "London"   "John_Nash"        "9234784546"  "foobar@gmail.com"

将以下内容附加到工作表的更改事件中...

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim ARng As Range
    Dim myRng As Range
    Dim iCnt As Long, iLoop As Long
    Dim found As Boolean

    Set ARng = ActiveSheet.UsedRange
    Set ARng = ARng.Cells(ARng.Rows.Count, 1)

    If Not Intersect(Target, ARng) Is Nothing Then 'Check the last cell in column A changed
        Set myRng = ActiveSheet.UsedRange
        iCnt = myRng.Rows.Count
        found = False
        Do While Not found And iCnt > 0 'Search for another instance from the bottom up
            iCnt = iCnt - 1
            found = Target.Value = myRng.Cells(iCnt, 1).Value
            If found Then 'found another instance so populate the row
                For iLoop = 2 To myRng.Columns.Count
                    myRng.Cells(myRng.Rows.Count, iLoop) = myRng.Cells(iCnt, iLoop)
                Next iLoop
            End If
        Loop
    End If
End Sub

从这个开始...

然后在单元格 A4 中输入 LON9501 得到这个...