Avatar of cbrune
cbrune

asked on 

VB script to take a pivot table and be able to parse it like the one attached.

example.xlsx

I need to know how to parse and get the value of the pivot table so I can grab the TTO than cycle through the subtasks.  I just want to get the tto without getting the total and if there was another TTO there how would i get that as well even though its crossing several rows.
VB Script

Avatar of undefined
Last Comment
Bill Prew
Avatar of Bill Prew
Bill Prew

Are you looking for something like this?

' Define Needed constants
Const xlUp = -4162

' Define Excel file to process
Const cExcelFile = "C:\EE\EE28226559\example.xlsx"

' Open Excel, hide it
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = False

' Access data from first sheets in first workbook
Set oMaster = oExcel.Workbooks.Open(cExcelFile, False, False)
Set oSheet = oMaster.Sheets(1)

' Iterate through all rows (skip header and total)
For iRow = 2 To oSheet.Cells(65536, "A").End(xlUp).Row - 1
   ' Get column A value when it changes
   sValue = Trim(oSheet.Cells(iRow, "A").Value)
   If sValue <> "" Then
      sTTO = sValue
   End If

   ' Get column B value when it changes
   sValue = Trim(oSheet.Cells(iRow, "B").Value)
   If sValue <> "" And sValue <> "Total" Then
      sSubTask = sValue
      Wscript.Echo sTTO & ", " & sSubTask
   End If
Next

oMaster.Close
oExcel.Quit

Open in new window

~bp
Avatar of cbrune
cbrune

ASKER

sorry i dont want u to think of it as an excel file, think of the data being in a pivot table object
Avatar of Bill Prew
Bill Prew

I'll need a real world example of the date you are trying to process.

~bp
Avatar of cbrune
cbrune

ASKER

well the data is the same but in a pivottable object.. with the column a spanning multiple rows
Avatar of Bill Prew
Bill Prew

Okay, so could you please prepare an actual excel workbook with the pivot table you want to pull data out of.  It's critical that the example you provide is exactly like the real files you will be working with, since extracting data from a pivot table relies on using the exact names of pivot fields, etc.

~bp
Avatar of cbrune
cbrune

ASKER

ok those are the exact names.. the pivot table is in memory so basically i outputed it into the excel document.
Avatar of Bill Prew
Bill Prew

What do you mean by "the pivot table is in memory"?  As I understood it you wanted to process an Excel file, but that doesn't sound like the situation.  If it isn't, then please describe further where the data is coming from?

~bp
Avatar of cbrune
cbrune

ASKER

yea so actually i am grabbing it from a pivottable in a qlikview application and need to process it and export a report to excel
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
VB Script
VB Script

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.

39K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo