mmsz_luwei提供需要解释的代码:
Public Sub harold_han() Dim i As Integer, m As Integer, s As Integer, p As Integer ‘声明变量 Sheet2.Select ’选取Sheet2工作表 m = [a65536].End(xlUp).Row ‘M为A列最的一个非空单元格的行数 Sheet1.Select ’选取Sheet1工作表 s = [a65536].End(xlUp).Row ‘S为(Sheet1工作表)A列最后一非空单元格的行数 For i = 1 To m ’设置i从1到M的循环 r = 2 ‘设置r的值为2 For p = 1 To s ‘设置P从1到s之间进行循环。 If Cells(p, 4) = Sheet2.Cells(i, 1) Then ‘如果单元格Cells(p, 4)和Sheet2.Cells(i, 1)的值相等,则 Sheet2.Cells(i, r) = Cells(p, 5) ’单元格Sheet2.Cells(i, r)值等于单元格Cells(p, 5)的值 r = r + 1 累计r的值(在原来值的基础上加1) End If Next p Next i
End Sub
|