Allow conditional formatting to update before continuing with rest of code?

Warwiz

New Member
Joined
Dec 4, 2017
Messages
6
I have code that runs multiple query's from the same Excel table and after each query is ran it saves it as a PDF file.
The code works great but on the larger query's it doesn't allow the conditional formatting to update before creating the PDF.
I have tried may ways of getting it to update the formatting using calculate, scroll off screen and back, wait function, doEvents etc with no success.
DoEvents allowed the smaller query's to update before saving but not the larger ones (even though I am probably not using it right)

I tried searching for a solution but there isn't much on this topic that I could find.
Maybe someone here can help?(oh and I am a very novice VBA'er .. trial, error, n google)
Using office 365 pro

After the query is ran, How do I allow time for any conditional formatting to update before performing the PDF save?

'Query1
Range("MATER_DISPO[#All]").AdvancedFilter Action _
:=xlFilterInPlace, CriteriaRange:=Range("AB1:AB2"), Unique:=False
Worksheets("Pending").Calculate
DoEvents
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="H:\Development" & Format(Date, "yyyy-mmm-dd") & Range("AB3").Value
'Query2
Range("MATER_DISPO[#All]").AdvancedFilter Action _
:=xlFilterInPlace, CriteriaRange:=Range("AC1:AC2"), Unique:=False
Worksheets("Pending").Calculate
DoEvents
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="H:\Development" & Format(Date, "yyyy-mmm-dd") & Range("AB3").Value
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Re: Excel - How do I allow conditional formatting to update before continuing with rest of code?

Have you tried:
Code:
Worksheets("Sheet1").EnableCalculation = False
Worksheets("Sheet1").EnableCalculation = True
which forces excel to do a recalculattion
 
Upvote 0
Re: Excel - How do I allow conditional formatting to update before continuing with rest of code?

Hi offthelip,

Yes, I did try enableCalculation false/true (and I tried it again to be sure)
If I run the query manually and then recalculate it updates conditional formatting just fine, or scroll down and back up etc.
 
Upvote 0
Re: Excel - How do I allow conditional formatting to update before continuing with rest of code?

did you set application.screenupdating = false
 
Upvote 0
Re: Excel - How do I allow conditional formatting to update before continuing with rest of code?

Hi Fazza,

Yes, in various different placements and in combination with calculations. Screen updating=False does not allow any conditional formats to update before saving the PDF file
 
Upvote 0
Re: Excel - How do I allow conditional formatting to update before continuing with rest of code?

Does setting 'application.screenupdating = true' before creating the pdf files fix the problem?
 
Upvote 0
Re: Excel - How do I allow conditional formatting to update before continuing with rest of code?

No, nothing seems to have influenced allowing the formatting to update except when I threw in DoEvents. Then the shorter Query's began to work.
With the large one it only updates about half the column before it saves.
Its not like the larger one is much bigger, its 166 rows.

Code:
Sub Saveall()
    Range("MATER_DISPO[#All]").AdvancedFilter Action _
        :=xlFilterInPlace, CriteriaRange:=Range("AA1:AA2"), Unique:=False
        Worksheets("InRepair").Calculate
        DoEvents
        Application.ScreenUpdating = True
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="H:\Development\" & Format(Date, "yyyy-mmm-dd") & Range("AA3").Value
 
Upvote 0
Re: Excel - How do I allow conditional formatting to update before continuing with rest of code?

what about exporting the same pdf twice? Delete the first one before exporting the second one.
 
Upvote 0
Re: Excel - How do I allow conditional formatting to update before continuing with rest of code?

I just tried that, deleting the 1st one then trying another.
Tried running it 3 times in a row and overwriting the file.
Part of the sort criteria is by the conditional format colors so would like to figure this out if possible before seeing if I can make due without the formatting.
 
Upvote 0
Re: Excel - How do I allow conditional formatting to update before continuing with rest of code?

If it isn't already, what if the conditional format is applied by the code?
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
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