Hey guys, welcome back. So in this video we're going to discuss calculate event. So the calculate event happens when you just calculate the values in your worksheet and the values get calculated whenever you change yourself, okay? And actually, this happens for the whole workbook, not just this particular sheet, however you're doing the event for for that particular sheet. So we are on a sheet called calculate event. And I've got some random numbers here in in these cells, okay?
And they are being generated by a function called run between. So this function will recalculate each time I changed the value of any other cell, okay, or any cell actually in the workbook. So if I just change the value of a cell numbers, recalculate, okay, and now I'm also going to show you how you can calculate a sheet or a workbook as well so you can go to the Formulas tab on the ribbon, click on calculate sheet and this will calculate your sheet. If you click on calculate now, the would calculate your entire workbook, which includes your sheet as well. I don't typically have a lot of uses for the for this event, like, I probably have never needed to use it. But in case you need it, it's there.
Okay, I'll show you as well, the example that Microsoft has on their websites. Okay, so this is the example that Microsoft has on their website. So it's actually just to autofit the columns A to F, whenever you do a calculation for the worksheet. It's not particularly you know, the best but we will try it. So I'm gonna right click on the calculate event worksheet here, click on View code, and then I'm gonna go to worksheet and select the calculate event. Okay?
And now we are in the worksheet calculate event. Okay? And now let's run this. Let's run this event. So I'm just going to change the value of any cell and this event will run you can see here that columns A to F have had an auto fitting, this is similar to selecting the columns here and double clicking on them and this will do the auto fitting and also there is a recalculation done. Okay.
And this will trigger your calculate event as well. And one thing I want to tell you as well, which is some sort of a word of caution, you know, this event will run whenever you do any sort of calculation on your workbook, okay? Because your workbook will recalculate for any cell that you change the value of, Okay, so this event will get triggered a lot. Okay, so if you've got some sort of any looping code, you know, any code that will take time to execute any code that has lots of actions, okay, this could slow down your workbook. I haven't needed to use it, but if there is a use for that event for you, I would be interested to know it basically. Okay.
So Thank you very much for watching this video. I'll see you on the next