大家好,我是陈小虾,是一名自动化方向的IT民工。写博客是为了记录自己的学习过程,通过不断输出倒逼自己加速成长。但由于水平有限,博客中难免会出现一些BUG,或者有更优方案恳请各位大佬不吝赐教!微信公众号:万能的Excel
功能说明:
本案例是应用在股票系统分析的时候,需要从原始数据的表格中,筛选出自己需要的一些数据,并生成TXT 文件
本工作表使用VBA实现了如下功能:
1、跨表格多条件筛选
2、在新表格输出结果
3、将结果生成TXT文件
关注公众号:万能的Excel 并回复【跨表格】获取源文件!
附上代码:
Private Sub CommandButton1_Click()
Dim d, ar, w%, j%, i As String, tempArr, str, t As String, dir As String
Set d = CreateObject("Scripting.Dictionary")
dir = Cells(1, 11)
Open ThisWorkbook.Path & "\" & dir & ".txt" For Output As #1
Application.ScreenUpdating = False
With GetObject(ThisWorkbook.Path & "\" & dir & ".xls")
ar = .Sheets(1).[a1].CurrentRegion: .Close 0
End With
For w = 2 To UBound(ar)
If ar(w, 4) <> "--" Then
tempArr = Split(ar(w, 1), ".")
If tempArr(1) = "SZ" Then
i = 0
ElseIf tempArr(1) = "SH" Then
i = 1
End If
Sheet1.Cells(w - 1, 1).Value = i + "|" + tempArr(0) + "|" + "【" + ar(w, 4) + "】"
t = "," + Sheet1.Cells(w - 1, 1)
Print #1, Mid(t, 2)
t = vbNullString
End If
Next
Close #1
End Sub