In this video, we're going to see how we can deal with named ranges in our VBA code. And a named ranges is a single cell or multiple cells that you can give a certain name to it. And then you can refer to that single cell or range of cells using that name instead of their of the cells name instead of saying c three, or a three, or C three to D, five, you can name that my table, for example, and just refer to it as my table. Okay, so to create a named range, you can select your cells First of all, so you can select a one to F 10, for example, and then go to this name box here, and then just write my underscore table. So I'll name it my table. Okay, and then press enter.
So now my table refers to that range of cells. So I've selected my table here, from the structure The menu, and then it's now referring to this range of cells, I can put a value into this range of cells. So I'll put a one till often to the equals 10. And then I can write equals sum, for example. And then I can refer to this range is my table, instead of selecting this range to be a one to F 10, or writing it as a one to F 10. And then if I hit Enter, it will give me the summation of that range of cells, okay?
And a range can be a single cell as well. So you can select a single cell and just name it Mali cell or whatever. And you can you can apply a name to a single cell. Okay, so let's see how we can deal with named ranges in our VBA code. So I'll delete that here. I'll do what I have done and then I'll right In New macro, so my name's range.
Okay, so it's very simple. We're just going to write range, and then open parentheses and then open double quotes and then write my underscore table. And you can see here that I've written it all in lowercase. And that won't make any differences. And the named range is originally having uppercase letters as the first letters on the two words on my end table, so I actually have written it all in lowercase. And that won't make any difference because Excel will ignore the difference in the casing of the letters.
Okay, so that won't cause any problems. So if I run the macro, you will just put the value of 10 in all the cells in that range. So it's very simple. You write range and then open parentheses and then open double quotes and you Write the name of the range and equals double quotes and close parentheses. And this is how you can refer to a named range. Okay, so thank you guys for watching this lecture and please follow me on to the next one.