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
Bookmarks