Hey guys, welcome back. So in this video we're going to discuss the before right click event. So before right click event does the same thing as the before double click event, except that it just triggers the code on right clicking instead of double clicking on a cell. Okay? So what happens when you right click on a cell so I'm going to right click so we get this menus. This is what happens when you right click on a cell, this is the default action.
Okay, so I'm going to right click here on my before right click worksheet and click on View code. And then I'm going to select from this menu. I'm going to select worksheet and I'm going to select it before right click. I'm just going to delete here the selection change event. And as you can see here, it's got two parameters the target as a range and the cancel as Boolean. So if you've guessed that the council will just disable that menu when right clicking Well, you did guess that true so let's say we want a message box.
Pop up only if we right click on cell C three. Okay? So we're going to do that. So if target dot address, and then we're going to put a full comma false so that I can write the the reference for the cell without the dollar signs, okay? equals c three, then messagebox. You right clicked cell C three, okay?
And if, okay, so if I right click on any cell, nothing's gonna happen, okay? Just any other cell other than cell C three. If I right click cell C threes, though, you get the message box. And notice here that it's been executed before, the default action for right clicking which is viewing the menu. Okay, so it gets executed before viewing the menu it whatever code you write gets executed before the menu pops up. Okay, so What if I don't want the menu to pop up?
Well, if you've guessed that we need to put a cancel the cancel equals true. Which is the similar to what we've done on the double click to a in order not to enter the cell editing mode. Well, that is true. Okay? So we need to put the cancel equals true. If we put the cancel equals true, we right click, and then you get the message box or whatever code you've written, executed, however, you don't get the menu.
Okay? So it works the same way, just as double clicking except it's for right clicking. Okay, so you can do some nice stuff with that. You could maybe have a form control pop up whenever you right click or something like that. Okay. So that's it for the before right click events.
It's very easy, and I'll see you on the next one.