|
设置好表名称为tj的条件表
委托方向
债券卖出
债券买入
然后 按操作步骤运行及可 通用型- Sub 单簿多表高级筛选()
- Dim Sht As Worksheet
- Dim xRow As Integer
- Dim yRow As Integer
- Sheets.Add After:=Sheets(Sheets.Count)
- ActiveSheet.Name = "合并结果"
- qsh = Val(Application.InputBox("请输入表头最末行号:", "拆分表格", "1"))
- bw = Val(Application.InputBox("请输入表尾的总行数, 没有就默认为0:", "拆分表格", "0"))
- Sheets("tj").Activate
- Set sxtj = Application.InputBox("请框选已设置好了的_ _筛选条件区域 :", Type:=8)
- a = MsgBox("是否去重处理", vbYesNo)
- Sheets("合并结果").Activate
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- For Each Sht In Worksheets
- bm = ActiveSheet.Name
- If Sht.Name <> bm And Sht.UsedRange.Rows.Count + Sht.UsedRange.Row - 1 > 1 And Sht.Name <> "tj" Then
- xRow = Sht.UsedRange.Rows.Count + Sht.UsedRange.Row - 1
- ls2 = Sht.UsedRange.Columns.Count + Sht.UsedRange.Column - 1
- Set myRange = Cells(1, ls2) '指定该列标号的任意单元格
- zmlh2 = Left(myRange.Range("A1").Address(True, False), _
- InStr(1, myRange.Range("A1").Address(True, False), "$", 1) - 1)
- If xRow > 1 Then
- yRow = Worksheets(bm).UsedRange.Rows.Count + Worksheets(bm).UsedRange.Row - 1
- If n > 0 Then GoTo 10
- Sht.Range("a1:" & zmlh2 & xRow - bw).Copy Worksheets(bm).Range("a" & yRow)
- GoTo 11
- 10:
- Sht.Range("A" & qsh + 1 & ":" & zmlh2 & xRow - bw).Copy Worksheets(bm).Range("a" & yRow + 1)
- End If
- 11:
- n = n + 1
- End If
- Next
- If qsh > 1 Then
- Rows("1:" & qsh - 1).Delete
- End If
- Application.ScreenUpdating = True
- Set zzd = Application.InputBox(prompt:="请选择这里提取需要的字段:点选按住Ctrl键 连续的可以框选):", Type:=8)
- Application.ScreenUpdating = False
- Sheets.Add After:=ActiveSheet
- ActiveSheet.Name = "筛选结果"
- For Each zd In zzd
- ss = ss + 1
- Cells(1, ss) = zd.Value
- Next zd
- For Each Sht In Sheets
- If Sht.Name = "合并结果" Then
- Myr = Cells(Rows.Count, 1).End(xlUp).Row + 1
- If Myr = 2 Then Myr = 1
- If a = 7 Then
- Sht.UsedRange.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=sxtj, CopyToRange:=Range(Cells(1, 1), Cells(1, ss)), Unique:=False
- Else
- Sht.UsedRange.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=sxtj, CopyToRange:=Range(Cells(1, 1), Cells(1, ss)), Unique:=True
- End If
- End If
- Next
- Worksheets("合并结果").Delete
- Application.DisplayAlerts = True '恢复警告
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|