我曾尝试使用多种解决方法和其他帖子,但似乎无法找到解决我遇到的错误的方法。
我正在使用Excel 2013,并尝试从表中获取信息以合并它。我还试图将表数据复制到另一个工作表上,希望这样可以更容易合并。但是,我仍然遇到同样的错误。
理想情况下,我想获取过滤后的表信息并合并它。需要合并的原因是它在表中有多个状态值,我需要根据状态(和其他变量)看到几个类别的总和。
请帮我弄清楚为什么代码不断破坏代码的整合部分。
Private Sub ComboBox2_Change()
Dim Issuer As String
Dim FirstRow As Long
Dim LastRow As Long
Dim LastCol As Long
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim MyArray As Variant
Set ws1 = Worksheets("Data")
Set ws2 = Worksheets("ChartData")
Issuer = ws2.Range("IssuerNum").Value
'Worksheets("Data").ListObjects("Table1").Range.AutoFilter.ShowAllData
If Issuer = "All" Then
Worksheets("Data").ListObjects("Table1").Range.AutoFilter _
Field:=1, Criteria1:="<>", Operator:=xlFilterValues
LastRow = ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row
FirstRow = ws1.Cells(2, 1).Row
Else
ws1.ListObjects("Table1").Range.AutoFilter _
Field:=1, Criteria1:=Issuer, Operator:=xlFilterValues
With ws1.ListObjects("Table1").AutoFilter.Range.SpecialCells(xlCellTypeVisible)
LastRow = .Areas(.Areas.Count).Row + .Areas(.Areas.Count).Rows.Count - 1
End With
FirstRow = ws1.ListObjects("Table1").AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Cells(1, 2).Row
End If
ws1.Range(ws1.Cells(FirstRow, 3), ws1.Cells(LastRow, 9)).Select
Set MyArray = Selection
'Add in consolidate here to set up chart data
If ws2.Range("RadioSel").Value = 1 Then
ws2.Range("A2").Consolidate _
Sources:=MyArray.Address(ReferenceStyle:=xlR1C1), _
Function:=xlSum, LeftColumn:=True
End Sub()