SOLVED

Need help with writing a more efficient line of code

Copper Contributor

I have an workbook with several sheets I'm working on.  I need help....I want to set a formula on one of the sheets without having to select that worksheet....that way I don't have flashing between sheets when the VBA code runs.

 

Example:

Sheet 1 = Workflow Summary

Sheet 2 - PFI (this is the sheet from which I am running the code)

 

'assume I am running this while on the PFI sheet

Sheets("WorkFlow Summary").Select
Range("J4").Select
ActiveCell.Formula = "=PFI!J2"

 

When I run this from the PFI sheet, the code flashes to the WorkFlow Summary sheet and then back to the PFI sheet.  It looks awful when you have a bunch of these that you need to run at the same time.

 

EDIT:  I would love to just say Sheets("WorkFlow Summary").Range("J4").ActiveCell.Formula ="=PFI!J2" , but that doesn't work

 

Thanks!!!

2 Replies
best response confirmed by CLAKES (Copper Contributor)
Solution

I'm not quite sure, if I understood it correct, but you can stop screen updating by using Application.ScreenUpdating = False at the start of your VBA code and then turn it back on again right before the end of your code by using Application.ScreenUpdating = True.

 

But beware, that you will not be able to see what the macro is doing.


For further reading see the documentation:
https://docs.microsoft.com/en-us/office/vba/api/excel.application.screenupdating
Hope it helps.

You rock! Works perfect. Thank you.
1 best response

Accepted Solutions
best response confirmed by CLAKES (Copper Contributor)
Solution

I'm not quite sure, if I understood it correct, but you can stop screen updating by using Application.ScreenUpdating = False at the start of your VBA code and then turn it back on again right before the end of your code by using Application.ScreenUpdating = True.

 

But beware, that you will not be able to see what the macro is doing.


For further reading see the documentation:
https://docs.microsoft.com/en-us/office/vba/api/excel.application.screenupdating
Hope it helps.

View solution in original post