Code not running in order.

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,342
Office Version
  1. 365
Platform
  1. Windows
When I run this code, its not completing the refresh of the table until after the part in the code that reformats the table. So basically when the table is finished refreshing, it removed the formatting

Is there a way to have this so that the formatting part doesn't happen until after the refreshing of the BoM table is done??

Sheets("BoM").ListObjects(1).QueryTable.Refresh
I thought the DoEvents would do what I needed.

Code:
Private Sub CommandButton1_Click()
'*Run the Refresh on the Proposal_Tasks table to update it to the selected Proposal

UserFormSP.Hide

UserFormX.Show vbModeless

'Application.ScreenUpdating = False

'*************************************************************
            UserFormX.LabelProg.Width = 65
            UserFormX.LabelProg.Caption = "36%"
            DoEvents
'*************************************************************

Sheets("Proposal Tasks").ListObjects(1).QueryTable.Refresh

'*************************************************************
            UserFormX.LabelProg.Width = 152
            UserFormX.LabelProg.Caption = "68%"
            DoEvents
'*************************************************************

Sheets("Proposal Tasks").Select

'*************************************************************
            UserFormX.LabelProg.Width = 176
            UserFormX.LabelProg.Caption = "76%"
            DoEvents
'*************************************************************

Sheets("BoM").ListObjects(1).QueryTable.Refresh

'*************************************************************
            UserFormX.LabelProg.Width = 176
            UserFormX.LabelProg.Caption = "82%"
            DoEvents
'*************************************************************

'* Format the BoM - Adds a blank row in-between each Task/BoM to make it visually easier
Sheet4.Select

    Dim col As String
    Dim col2 As String
    Dim i As Long
    Dim startRow As Long
    Dim lastRow As Long
    
    col = "F"
    col2 = "A"
    startRow = 4

        lastRow = Cells(Rows.Count, col).End(xlUp).Row
    
    With ActiveSheet
         
        For i = lastRow To startRow Step -1
        
            If Range("F" & i).Value = "1" Then
                .Cells(i, col).EntireRow.Insert shift:=xlDown
            End If
            
            If Range("A" & i).Value = "" Then
                .Cells(i, col).EntireRow.RowHeight = 9
            End If
            
        Next i
        
    End With
    
    
'*************************************************************

            UserFormX.LabelProg.Width = 198
            UserFormX.LabelProg.Caption = "99%"
            DoEvents
'*************************************************************


UserFormX.Hide

MsgBox "On the BoM tab reviewed selected cost, modifiy selected cost or add new selected cost sources."

End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I turned off the "Enable background refresh" in the query properties. That seems to have fixed it.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,544
Messages
6,125,434
Members
449,223
Latest member
Narrian

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