1

I have an SQL Server connected excel workbook in which I am trying to execute three VBA macros in order

  1. Refresh all connections (data and charts)
  2. Copy all values from the from a summary sheet and past as values
  3. Copy a range of values from summary sheet and paste to another

I created a macro called RunAllMacros to execute in that order. For some reason it says it is connecting to the data source and running the SQL but on the summary page there are a number of formulas to show the updated results. For some reason it does not update those numbers when ran together. When I run the first (refresh all connections) macro it works fine - the numbers are updated. Any idea what might be going on here? Just to note I am quite a novice at VBA.

VBA:

Private Sub RefreshAllConnections()
'This step uses the RefreshAll method
    Workbooks(ThisWorkbook.Name).RefreshAll
End Sub

Private Sub CopyPasteAsValues()
'This step copies the summary sheet and pastes as values
    Sheets("Summary").Activate
    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
End Sub

Private Sub PasteChartData()
'This step pastes the range of values to the chart data tab
    Sheets(1).Range("A6:J24").Copy _
    Destination:=Sheets("Chart Data").Cells(Sheets("Chart Data").Rows.Count, 1).End(xlUp).Offset(1, 0)
End Sub

Sub RunAllMacros()
        RefreshAllConnections
        CopyPasteAsValues
        PasteChartData
End Sub
Community
  • 1
  • 1
user3496218
  • 185
  • 3
  • 5
  • 19

0 Answers0