excel VBA代码问题

Private Sub CommandButton1_Click()
Range("c:c").Replace ",", ""

Range("L2:R" & Range("R65536").End(xlUp).Row).ClearContents

Dim ArrYS
Dim d As Object
Dim i&
ArrYS = Range("B2:B" & Range("B65536").End(xlUp).Row)
Set d = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(ArrYS)
d(ArrYS(i, 1)) = d(ArrYS(i, 1)) + 1
Next i
Range("L2").Resize(d.Count, 1) = WorksheetFunction.Transpose(d.keys)

Range("M2").Select
ActiveCell.Formula = "=VLOOKUP(L2,B:C,2,0)"
Selection.AutoFill Destination:=Range("M2:M" & Range("L65536").End(xlUp).Row)
Range("N2").Select
ActiveCell.Formula = "=VALUE(RIGHT(VLOOKUP(L2,B:D,3,0),6))"
Selection.AutoFill Destination:=Range("N2:N" & Range("L65536").End(xlUp).Row)
Range("O2").Select
ActiveCell.FormulaR1C1 = "=SUMIFS(C[-8],C[-13],RC[-3])"
Selection.AutoFill Destination:=Range("O2:O" & Range("L65536").End(xlUp).Row)
Range("P2").Select
ActiveCell.Formula = "=COUNTIF($B:$B,$L2)+COUNTIF(存款总次数!$A:$A,IF(LEN(N2)=5,VALUE(z000000&N2),VALUE(z00000&N2)))"
Selection.AutoFill Destination:=Range("P2:P" & Range("L65536").End(xlUp).Row)
Range("Q2").Select
ActiveCell.Formula = "=IFERROR(VLOOKUP(M2,代码!A:B,2,0),"""")"
Selection.AutoFill Destination:=Range("Q2:Q" & Range("L65536").End(xlUp).Row)
Range("R2").Select
ActiveCell.Formula = "=COUNTIF(注册!$B:$B,L2)"
Selection.AutoFill Destination:=Range("R2:R" & Range("L65536").End(xlUp).Row)
End Sub

如题这是一段VBA代码,主要是谁能告诉我,这段代码是什么?大概讲解一下,用了什么语句,用了什么结构。把相应语句的结构告诉我一下

第1个回答  推荐于2016-09-15
代码大致功能:
1、去掉C列中的逗号
2、清空L至R列的数据(从第二行开始到R列的最后有数据的行)
3、将B列的数据(第二行开始)利用字典去重放入L列(第二行开始)
4、设置M2公式=VLOOKUP(L2,B:C,2,0),并向下填充
5、设置N2公式=VALUE(RIGHT(VLOOKUP(L2,B:D,3,0),6)),并向下填充
6、设置O2公式=SUMIFS(C[-8],C[-13],RC[-3]),并向下填充
7、设置P2公式=COUNTIF($B:$B,$L2)+COUNTIF(存款总次数!$A:$A,IF(LEN(N2)=5,VALUE(z000000&N2),VALUE(z00000&N2))),并向下填充
8、设置Q2公式=IFERROR(VLOOKUP(M2,代码!A:B,2,0),""),并向下填充
9、设置R2公式=COUNTIF(注册!$B:$B,L2),并向下填充
语句:
1、Range("R65536").End(xlUp).Row 表示R列最后有数据的行
2、Set d = CreateObject("Scripting.Dictionary") 字典对象,这里主要是应用其key的唯一行来去重
3、Range("L2").Resize(d.Count, 1) = WorksheetFunction.Transpose(d.keys) resize扩充,这里就是将L2变成 L2:L(d.count+1) ,比如 d.count=10,那么这里就是L2:L11,也就是向下扩充d.count-1行,向后扩充1-1=0列,然后将数组数据放入其中
4、Range("M2").Select 表示 选中M2单元格
5、ActiveCell.Formula ActiveCell 当前选中的单元格 Formula 就是公式
6、Selection.AutoFill Destination:=Range("M2:M" & Range("L65536").End(xlUp).Row) selection 表示选中的单元格 ,autofill就是自动填充,Destination 表示填充的位置,这里就是M列从第二行开始至最后有数据的行本回答被提问者采纳
相似回答