Home > other >  "Call" macro does not execute but will manually
"Call" macro does not execute but will manually

Time:11-03

Does anyone know why my macro to "call" other macros is not running the last macro called SetupDetails? It runs successfully when pushed manually/individually.

Sub MainMacro()

  Application.ScreenUpdating = False
   Call InjectAllSqlsAndRefreshConnections
   Call SetupDashboard
   Call SetupDetails
   Application.ScreenUpdating = True

End Sub

Is there something wrong with the body of this SetupDetails macro itself? I've fiddled with it a lot and nothing seems to be solve this issue.

Sub SetupDetails()

Set Details = ThisWorkbook.Sheets("Details")
Set Raw = ThisWorkbook.Sheets("SQL - Bugs w Goals")

Dim x As Integer
Dim CorrectOrder As Variant
Dim i As Variant
Dim tblComp As ListObject
Dim LastRow As Integer

Details.Activate
Details.UsedRange.Clear
If Raw.AutoFilterMode Then Raw.ShowAllData
Raw.UsedRange.Copy
Details.Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats

With Details.UsedRange
        'Dedupe
        .AutoFilter Field:=23, Criteria1:="0"
        .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
        .AutoFilter

        'Delete unneeded columns
        .Range("D:E,G:G, I:K, M:N, O:P,R:U, W:Z, AD:AD, AF:AG,AK:AK").Delete

        'Rename Columns
        .Range("A1").Value = "ID"
        .Range("B1").Value = "Summary"
        .Range("C1").Value = "Status"
        .Range("E1").Value = "Class"
        .Range("H1").Value = "Goals"
        .Range("I1").Value = "Progress Status"
        .Range("J1").Value = "Open/Closed Status"
        .Range("K1").Value = "Blocked Status"
        .Range("M1").Value = "Remaining Time"
        .Range("N1").Value = "Total Time"
        .Range("O1").Value = "Dept"

        Application.CutCopyMode = False
        Details.ListObjects.Add(xlSrcRange, Details.UsedRange, xlYes).Name = "DetailsView"
        Details.ListObjects("DetailsView").TableStyle = "TableStyleLight9"

        'Reorder
        Set tblComp = Details.ListObjects("DetailsView")
        CorrectOrder = Array("Goals", "Dept", "Team", "ID", "Status", "Class", "Summary", "Due Date", "Deadline Stage (Milestone)", "Actual Time", "Remaining Time", "Total Time", "Progress Status", "Open/Closed Status", "Blocked Status")
        On Error Resume Next
        For Each i In CorrectOrder
            Columns(tblComp.ListColumns(i).Range.Column).Cut
            Columns(tblComp.ListColumns.Count   1).Insert Shift:=xlToRight
        Next i
        On Error GoTo 0


End With

'Formatting
With Details
            .Columns(1).ColumnWidth = 60
            .Columns(1).WrapText = True
            .Columns(7).ColumnWidth = 60
            .Columns(7).WrapText = True
            For x = 1 To .Columns.Count
                Columns(x).EntireColumn.AutoFit
            Next x
            Cells.Select
            Selection.Columns.AutoFit
End With

'Links
LastRow = Details.Cells(Details.Rows.Count, "D").End(xlUp).Row
With Details.UsedRange
                        For x = 2 To LastRow
                            Cells(x, "D").Activate
                            .Hyperlinks.Add Anchor:=ActiveCell, Address:="URL HERE" & ActiveCell.Text, TextToDisplay:=ActiveCell.Text
                            Next x
    End With
    
    Sheets("Report").Activate
    
    End Sub

CodePudding user response:

I was able to figure this out! Turns out the macro InjectAllSqlsAndRefreshConnections, which does exactly what it sounds like was not completing the data refresh until it continued on. So any macros afterwards which depend on the refreshed data were appearing unchanged as it was still using the unrefreshed data.

Solved this by turning off Enable Background Refresh in the data query Connection Properties. This way it forces the query to complete before continuing processing.

Image

  • Related