VBA Copying/Pasting Data from PivotTable Macro

turbo805

New Member
Joined
Oct 24, 2016
Messages
22
Greetings everyone!

I'm working on a macro to do my daily copying/pasting for me. It works by copying data from a daily updated PivotTable and pasting it in the correct sheet/cell location.

Here's a picture of my table just to give you an idea of how my data is set up: https://paste.pics/736a2e7214ab0f103596ab4d5cf5f9b1

Here's my code:
Code:
Sub TEST()'
' TEST Macro


Dim OrganicClicks As Integer
Dim OrganicLeads As Integer
Dim OrganicCons As Integer


'adwordsKLS'
Sheets("PivotTable").Select
Range("A8").Select
Do Until ActiveCell = "adwordsKLS"
        ActiveCell.Offset(1, 0).Select
        Loop
        Range(ActiveCell.Offset(0, 1), ActiveCell.Offset(0, 3)).Select
        Application.CutCopyMode = False
        Selection.Copy
        Sheets("Google Search").Select
        Range("D5").Select
        Do Until ActiveCell = ""
        ActiveCell.Offset(0, 1).Select
        Loop
        Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
        Application.CutCopyMode = False
        
        'formating'
        With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent5
        .TintAndShade = 0.799981688894314
        .PatternTintAndShade = 0
    End With
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Selection.Font.Bold = False


'con2med'
Sheets("PivotTable").Select
Range("A8").Select
Do Until ActiveCell = "con2med"
        ActiveCell.Offset(1, 0).Select
        Loop
        Range(ActiveCell.Offset(0, 1), ActiveCell.Offset(0, 3)).Select
        Application.CutCopyMode = False
        Selection.Copy
        Sheets("Misc.").Select
        Range("D75").Select
        Do Until ActiveCell = ""
        ActiveCell.Offset(0, 1).Select
        Loop
        Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
        Application.CutCopyMode = False
        
        'formating'
        With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent5
        .TintAndShade = 0.799981688894314
        .PatternTintAndShade = 0
    End With
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Selection.Font.Bold = False
End

It works in two parts by searching for a correct category "adwordsKLS" and then posting the data in the correct spot with formatting. I planned to do this with every category in my table.

My error comes from within these categories. For example, on some days the category "adwordsKLS" might not exist, causing my code to loop looking for it. I understand the error i'm just not savvy enough to figure out a work around (self-learning is hard, yikes).

Thanks Excel heroes.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Bump. To clarify a little more I will always have a set number of categories with given names but not every category will appear daily.
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,855
Members
449,096
Latest member
Erald

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