原创

VBA编程备忘录2

1. 读取sheet页【原始数据】中的B列只取唯一值,并将维一值写入到sheet页【批量处理】A列中

Sub only_data()
Dim mRng$, D, c

Set D = Create Object("scripting.dictionary")  ' 因MSSQL防注入安全问题,这里的Create与Object之间是没有空格才是正确

For Each c In Sheets("原始数据").Range("B2:B9999")
If Not D.exists(c.Value) Then D.Add c.Value, ""
Next c
Sheets("批量处理").Range("A3").Resize(UBound(D.keys) + 1, 1) = WorksheetFunction.Transpose(D.keys)
D = ""
End Sub

 

16 文件另存
Sub savefile()
Dim N_NAME, N_PATH
N_PATH = ThisWorkbook.Path '定义保存路径,可自己定义保存位置
N_NAME = N_PATH & "\XXXXX.xls" '定义保存文件路径及文件名
ActiveWorkbook.SaveAs N_NAME
End Sub

 
正文到此结束
本文目录