Excel VBA - Array & Range - Help Required

iGavC

New Member
Joined
Aug 1, 2019
Messages
3
Hi,

I was wondering if anyone could assist.
I'm currently asking my VBA Code to create a multiple consolidated range with a data set I have. It's currently reference within a table which I've named: "Client_MI"

Right now, the data set it going to the 5000th row down. Can I point my range to just simply go to the end of the data source?:

Please see below:
Sub Create_Data_Table()

' Removes alerts

Application.DisplayAlerts = False

' Runs Multiple Consolidated Ranges for Data Table

ActiveWorkbook.PivotCaches.Create(SourceType:=xlConsolidation, SourceData:= _
Array("'Client - MI Report'!R2C66:R5000C188"), Version:=xlPivotTableVersion14). _
CreatePivotTable TableDestination:="", TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion14
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(2, 1)
ActiveSheet.Cells(2, 1).Select
ActiveSheet.PivotTables("PivotTable1").DataPivotField.PivotItems( _
"Count of Value").Position = 1

Application.DisplayAlerts = True

End Sub



Appreciate any assistance on this.

Thank you
Kind regards
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi,

You could add a variable

Code:
Dim last As Long
last = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
' and then amend your instruction
[I]Array("'Client - MI Report'![COLOR=#ff0000]BN2:GF" & last[/COLOR])[/I]

Hope this will help
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,312
Members
448,564
Latest member
ED38

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