+ Reply to Thread
Results 1 to 2 of 2

Have macro looking at column in summary sheet and matching to data in pivot table

  1. #1
    Registered User
    Join Date
    05-26-2015
    Location
    Rolla, MO
    MS-Off Ver
    2010
    Posts
    6

    Have macro looking at column in summary sheet and matching to data in pivot table

    I have a macro that will be running automatically and drawing a blank on this one option.

    I have a spreadsheet that pulls data in each month, deletes the duplicates and then puts the data to a pivot table. I then need it to pull the data from the pivot table and place in the correct column and row on the summary sheet. This is what I have so far and know it is an easy fix but have tried everything and cannot get it to move the data down one row at a time in my loop to compare the name with the name on the pivot table. I need the "A2" to move down a row as it loops.

    Code:

    Sub GetSummaryData()

    ' Add the data from the pivot table to the correct column on the Summary Sheet

    Dim MonthData As String 'Store the value of the month we want the data to match from month to Summary Column month
    Dim curRow As Long 'Store the row the data needs to go into for the indicated month
    Dim ThisRange As Range
    Dim strLocData As String 'Store the the data being pulled from the pivot table to the summary sheet

    'Set Variables
    MonthData = ""
    strLocData = " "
    start_row = 2
    end_row = 10

    'Get the sheet name to match to the column
    MonthData = ActiveSheet.Name

    'Move to the Summary Sheet
    Sheets("Summary").Activate

    'Move the cursor to the correct column for the month the data is to be entered
    Range(MonthData).Select

    curRow = 2

    Do While curRow < 10

    ActiveCell.Offset(1, 0).Select
    srtLocData = ThisWorkbook.Worksheets("Summary").Range("A2").Value

    Select Case srtLocData
    Case "AMS"
    ActiveCell.FormulaR1C1 = _
    "=GETPIVOTDATA(""ACCT #"",Apr!R2C9,""LOCATION"",""AMS "")"
    ActiveCell.Select

    Case "AR"
    ActiveCell.FormulaR1C1 = _
    "=GETPIVOTDATA(""ACCT #"",Apr!R2C9,""LOCATION"",""AR "")"
    ActiveCell.Select

    Case "ICU"
    ActiveCell.FormulaR1C1 = _
    "=GETPIVOTDATA(""ACCT #"",Apr!R2C9,""LOCATION"",""ICU "")"
    ActiveCell.Select

    Case "MO"
    ActiveCell.FormulaR1C1 = _
    "=GETPIVOTDATA(""ACCT #"",Apr!R2C9,""LOCATION"",""MO "")"
    ActiveCell.Select

    Case "OB"
    ActiveCell.FormulaR1C1 = _
    "=GETPIVOTDATA(""ACCT #"",Apr!R2C9,""LOCATION"",""OB "")"
    ActiveCell.Select

    Case "PEDS"
    ActiveCell.FormulaR1C1 = _
    "=GETPIVOTDATA(""ACCT #"",Apr!R2C9,""LOCATION"",""PEDS "")"
    ActiveCell.Select

    Case "SNF"
    ActiveCell.FormulaR1C1 = _
    "=GETPIVOTDATA(""ACCT #"",Apr!R2C9,""LOCATION"",""SNF "")"
    ActiveCell.Select

    Case "SO"
    ActiveCell.FormulaR1C1 = _
    "=GETPIVOTDATA(""ACCT #"",Apr!R2C9,""LOCATION"",""SO "")"
    ActiveCell.Select

    Case Else: ActiveCell.Value = 0

    End Select

    curRow = curRow + 1
    curLocNum = curLocNum + 1


    Loop

    End Sub

  2. #2
    Registered User
    Join Date
    05-26-2015
    Location
    Rolla, MO
    MS-Off Ver
    2010
    Posts
    6

    Re: Have macro looking at column in summary sheet and matching to data in pivot table

    I figured it out and do I feel stupid. Changed this:
    srtLocData = ThisWorkbook.Worksheets("Summary").Range("A2").Value

    to this:
    srtLocData = ThisWorkbook.Worksheets("Summary").Cells(curRow, "A").Value

    and it works and moves down a row and checks the name to put the value in the field.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problems with Summary and Pivot Table creation macro
    By Handyann in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-07-2015, 09:31 AM
  2. [SOLVED] Bring Pivot table totals to summary sheet
    By ZuneidDassu in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 04-04-2014, 06:03 AM
  3. [SOLVED] Pivot Table Summary -- Part #'s do not show in Pivot but data is in worksheet
    By maryren in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 09-19-2013, 10:51 AM
  4. matching the column with a value from pivot table
    By mumsys in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-29-2013, 02:29 PM
  5. Replies: 12
    Last Post: 08-23-2012, 08:16 AM
  6. Pivot Table Data summary settings
    By Jerry.Peoples in forum Excel General
    Replies: 6
    Last Post: 04-19-2010, 08:24 AM
  7. Pivot Table Summary of Raw Data
    By bee3902 in forum Excel General
    Replies: 1
    Last Post: 12-18-2009, 09:28 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1