Application-defined or object-defined error when trying to consolidate

mikhailj

New Member
Joined
Nov 5, 2015
Messages
5
I have tried to use several workarounds and other posts, but cannot seem to find a way to answer the error I am having.

I am using Excel 2013 and am trying to grab information from a table to consolidate it. I could not get the range to work so I eventually added in the three lines before "'Add in consolidate here to set up chart data". I was hoping to be able to copy the table data somewhere else and that this would make it easier to consolidate. However, I am still having the same error above with the information that I copied to T1.

Ideally, I would like to remove those three rows of code and find a way to grab the filtered table information and consolidate it. The reason it needs to be consolidated is that it will have multiple values for state in the table and I need to see the sum of a few categories based off of state (and other variables).

If I have to copy the data to another location (like the code is currently), then that is fine as well. Please help me figure out why the code keeps on breaking at the consolidate piece of the code.

Code:
 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 wkbk As Workbook
Dim MyArray As Variant


Set wkbk = ActiveWorkbook
Set ws1 = Worksheets("Data")
Set ws2 = Worksheets("ChartData")
Issuer = ws2.Range("IssuerNum").Value


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)).Copy Destination:=ws2.Range("T1")
LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "T").End(xlUp).Row
LastCol = ActiveSheet.Range("T1").SpecialCells(xlCellTypeLastCell).Column


'Add in consolidate here to set up chart data
If ws2.Range("RadioSel").Value = 1 Then
ws2.Range("A2").Consolidate _
   Sources:=ws2.Range(ws2.Cells(1, 20), ws2.Cells(LastRow, 26)), _
   Function:=xlSum, LeftColumn:=True
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,214,827
Messages
6,121,816
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top