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
 

Some videos you may like

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

James006

Well-known Member
Joined
Apr 4, 2009
Messages
3,680
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
 

Watch MrExcel Video

Forum statistics

Threads
1,102,682
Messages
5,488,240
Members
407,632
Latest member
varunwalla

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top