I have very long VBA code in my Excel to run a lot of processes before exporting every sheet to PDF. While running it I use:
Application.ScreenUpdating = False
Application.ScreenUpdating = True
The problem is that it doesn't help and my screen keeps updating anyway or at least blinking sometimes black and sometimes white. I am thinking that maybe command .Select
is causing this problem? Here is one part of my code:
ActiveWorkbook.Sheets("MAIN").Select
For Each cel In Range("AX7:AX120")
If cel.Value = 1 Then
cel.Offset(0, -43).Font.Bold = True
cel.Offset(0, -44).Font.Bold = True
cel.Offset(0, -45).Font.Bold = True
cel.Offset(0, -46).Font.Bold = True
End If
Next
lastRow = [LOOKUP(2,1/(D1:D65536<>""),ROW(D1:D65536))]
Sheets("MAIN").PageSetup.PrintArea = Sheets("MAIN").Range("A1:Z" & lastRow).Address
---------------------- EDIT ---------------------------
I have made changes, but this is not working:
Dim printareaMain As Worksheet
Set printareaMain = Sheets("MAIN")
For Each cel In printareaMain.Range("AX7:AX120")
If cel.Value < 3 Then
cel.Offset(0, -43).Font.Bold = True
cel.Offset(0, -44).Font.Bold = True
cel.Offset(0, -45).Font.Bold = True
cel.Offset(0, -46).Font.Bold = True
End If
Next
'lastRow = [LOOKUP(2,1/(D1:D65536<>""),ROW(D1:D65536))]
printareaMain.PageSetup.PrintArea = printareaMain.Range("A1:Z" & [LOOKUP(2,1/(D1:D65536<>""),ROW(D1:D65536))]).Address
Following part of the code is doing nothing:
printareaMain.PageSetup.PrintArea = printareaMain.Range("A1:Z" & [LOOKUP(2,1/(D1:D65536<>""),ROW(D1:D65536))]).Address