VBA Copy/Paste is sometimes pasting the wrong/previous value

ddander54

Board Regular
Joined
Oct 18, 2012
Messages
97
My problem is that 'sometimes' the code in the Copy/Paste section is not pasting the correct value. I have multiple versions of this code attached to buttons that sets up the workbook different ways for different people, first doing all the filtering with the slicer caches, then copy/paste the values that the filters provided.

It seems like sometimes it will copy/paste a value from a previous filter, THEN, filter the data correctly, or maybe its putting the old copy value in memory to early and then pastes it rather than the newly filtered value....if that makes sense.

Where I see it most is when it copies AZ10 to BE1. AZ10 is where I always copy from, each macro (slicer filters) will drive a different value to AZ10, then I copy from AZ10 to BE1 thru BE14, depending on the macro that's being run. So if the previous value in AZ10 was 42002 and was copied to BE2, then I run the code below, it might copy 42002 to BE1 rather than the new value 314198.

Code:
Sub ALL_IT_Dashboard()
'
' ALL_IT_Dashboard Macro
'
    With Sheets("Dashboard")
        Range("A5:A19").Font.ColorIndex = 1 'Black
        Range("U2").Font.ColorIndex = 3 'Red
'        Range("A5").Font.ColorIndex = 3
    End With
    
'
    With Application
       .ScreenUpdating = False
       .Calculation = xlCalculationManual
'       .EnableEvents = False
    End With
'    Sheets("Dashboard").Select
    ActiveWorkbook.SlicerCaches("Slicer_Client1").ClearManualFilter
    ActiveWorkbook.SlicerCaches("Slicer_PPM").ClearManualFilter
    ActiveWorkbook.SlicerCaches("Slicer_Billable_Type1").ClearManualFilter
    
'    Sheets("2018FilteredProjectPivotbyClien").Select
    ActiveWorkbook.SlicerCaches("Slicer_Client").ClearManualFilter
    ActiveWorkbook.SlicerCaches("Slicer_PPM1").ClearManualFilter
    ActiveWorkbook.SlicerCaches("Slicer_Billable_Type").ClearManualFilter
     
     'Copy Break/Fix Hours to table for Chart
    Worksheets("2018FilteredProjectPivotbyClien").Activate
    Range("BS14").Select
    Selection.Copy
    Range("AZ8").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.NumberFormat = "0"
    
    'Copy Planned Hours to table for % of work calculation
    Worksheets("2018FilteredProjectPivotbyClien").Activate
    Range("AZ10").Select
    Selection.Copy
    Range("BE1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.NumberFormat = "0"
    
    'Copy % of work value to Dashboard/Total_Res_Capacity worksheet
    Worksheets("2018FilteredProjectPivotbyClien").Activate
    Range("BG1").Select
    Selection.Copy
    Worksheets("Dashboard").Activate
    'Sheets("Dashboard").Select
    Range("AJ2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Worksheets("2018FilteredProjectPivotbyClien").Activate
    ActiveWindow.ScrollColumn = 49
    Worksheets("Dashboard").Activate
    Range("I1").Select
    
    With Application
       .ScreenUpdating = True
       .Calculation = xlCalculationAutomatic
'       .EnableEvents = True
    End With
    
    MsgBox ("Successfully Completed the Task.")
    
End Sub

Thanks,
Don
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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