首页->【软件工具包使用(SW/Software Tools Usage)】

4 1

Option Explicit

'Dsn:Winyoo_shiy

'Location:Shanghai,PRC

'ReleaseDate:10/14/18

Public Sub AutoFill()

   Dim StartPosition As Integer
   Dim EndPosition   As Integer
   Dim CustomerName(9) As String
   Dim CustomerInfo(9) As String

   Dim i As Integer
   Dim cnti As Integer
   
   Dim c   As Variant
   Dim p   As Variant
   
   Dim CellRow As Integer
   Dim CellCol As Integer
   
   
   'Dim CustomerInfoCol As Integer
   i = 0
   Sheet2.Activate
   StartPosition = 2
   EndPosition = 11

   For cnti = StartPosition To EndPosition
        With Sheet2
            CustomerName(i) = .Cells(cnti, 1).Value
            i = i + 1
         End With
   Next cnti
Sheet1.Activate
For i = 0 To 9
    With ActiveSheet.Range("A2:A41")
        Set c = .Find(CustomerName(i), , , xlWhole, xlByColumns, xlNext, False)
        If Not c Is Nothing Then
                p = c.Address
                CellRow = c.Row
                CellCol = c.Column
                Do
                    Set c = .FindNext(c)
               Loop While Not c Is Nothing And c.Address <> p
    With Sheet1
                CustomerInfo(i) = .Cells(CellRow, CellCol + 1).Value
    End With
    End If
End With
Next i
      
'CustomerInfoCol = 2

Sheet2.Activate
With Sheet2
    .Range("B2:B11").Select
     For cnti = StartPosition To EndPosition
    .Cells(cnti, 2).Value = CustomerInfo(cnti - 2)
    Next cnti
End With
End Sub

楼主可见

  1. shwnyoo 1#

    ***此内容已隐藏,只有楼主可见***