Selecting Sheets

Excel VBA for Beginners 5- Dealing with Worksheets
5 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€87.82
List Price:  €122.96
You save:  €35.13
£75.16
List Price:  £105.22
You save:  £30.06
CA$138.43
List Price:  CA$193.81
You save:  CA$55.37
A$156.59
List Price:  A$219.24
You save:  A$62.64
S$131.16
List Price:  S$183.63
You save:  S$52.46
HK$775.77
List Price:  HK$1,086.11
You save:  HK$310.34
CHF 82.51
List Price:  CHF 115.51
You save:  CHF 33
NOK kr1,042.39
List Price:  NOK kr1,459.39
You save:  NOK kr417
DKK kr655.69
List Price:  DKK kr918
You save:  DKK kr262.30
NZ$167.31
List Price:  NZ$234.24
You save:  NZ$66.93
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳12,147.63
List Price:  ৳17,007.17
You save:  ৳4,859.53
₹8,526.15
List Price:  ₹11,936.95
You save:  ₹3,410.80
RM437.25
List Price:  RM612.17
You save:  RM174.92
₦161,582.84
List Price:  ₦226,222.44
You save:  ₦64,639.60
₨28,083.99
List Price:  ₨39,318.71
You save:  ₨11,234.71
฿3,343.46
List Price:  ฿4,680.98
You save:  ฿1,337.52
₺3,831.60
List Price:  ₺5,364.40
You save:  ₺1,532.79
B$572.90
List Price:  B$802.08
You save:  B$229.18
R1,870.82
List Price:  R2,619.22
You save:  R748.40
Лв171.98
List Price:  Лв240.78
You save:  Лв68.80
₩143,528.93
List Price:  ₩200,946.25
You save:  ₩57,417.31
₪364.89
List Price:  ₪510.86
You save:  ₪145.97
₱5,649.88
List Price:  ₱7,910.06
You save:  ₱2,260.18
¥14,243.72
List Price:  ¥19,941.78
You save:  ¥5,698.06
MX$1,958.93
List Price:  MX$2,742.58
You save:  MX$783.65
QR364.07
List Price:  QR509.71
You save:  QR145.64
P1,365.84
List Price:  P1,912.23
You save:  P546.39
KSh12,938.70
List Price:  KSh18,114.70
You save:  KSh5,176
E£5,095.17
List Price:  E£7,133.44
You save:  E£2,038.27
ብር13,416.63
List Price:  ብር18,783.83
You save:  ብር5,367.19
Kz91,190.88
List Price:  Kz127,670.88
You save:  Kz36,480
CLP$94,266.88
List Price:  CLP$131,977.40
You save:  CLP$37,710.52
CN¥728.62
List Price:  CN¥1,020.10
You save:  CN¥291.48
RD$5,931.15
List Price:  RD$8,303.85
You save:  RD$2,372.70
DA13,230.85
List Price:  DA18,523.73
You save:  DA5,292.87
FJ$226.02
List Price:  FJ$316.44
You save:  FJ$90.41
Q770.12
List Price:  Q1,078.20
You save:  Q308.07
GY$20,916.83
List Price:  GY$29,284.40
You save:  GY$8,367.57
ISK kr12,726.72
List Price:  ISK kr17,817.92
You save:  ISK kr5,091.20
DH925.43
List Price:  DH1,295.64
You save:  DH370.21
L1,727.39
List Price:  L2,418.42
You save:  L691.02
ден5,403.80
List Price:  ден7,565.54
You save:  ден2,161.73
MOP$799.06
List Price:  MOP$1,118.72
You save:  MOP$319.65
N$1,856.77
List Price:  N$2,599.55
You save:  N$742.78
C$3,679.18
List Price:  C$5,151.01
You save:  C$1,471.82
रु13,655.87
List Price:  रु19,118.77
You save:  रु5,462.89
S/369.72
List Price:  S/517.62
You save:  S/147.90
K407.72
List Price:  K570.82
You save:  K163.10
SAR375.06
List Price:  SAR525.10
You save:  SAR150.04
ZK2,836.90
List Price:  ZK3,971.77
You save:  ZK1,134.87
L437.14
List Price:  L612.02
You save:  L174.87
Kč2,196.89
List Price:  Kč3,075.74
You save:  Kč878.84
Ft35,797.65
List Price:  Ft50,118.14
You save:  Ft14,320.49
SEK kr961.88
List Price:  SEK kr1,346.67
You save:  SEK kr384.79
ARS$116,335.31
List Price:  ARS$162,874.09
You save:  ARS$46,538.78
Bs690.85
List Price:  Bs967.22
You save:  Bs276.37
COP$430,007.65
List Price:  COP$602,027.91
You save:  COP$172,020.26
₡50,277.57
List Price:  ₡70,390.61
You save:  ₡20,113.04
L2,591.91
List Price:  L3,628.78
You save:  L1,036.87
₲799,756.92
List Price:  ₲1,119,691.68
You save:  ₲319,934.76
$U4,193.03
List Price:  $U5,870.41
You save:  $U1,677.38
zł375.98
List Price:  zł526.39
You save:  zł150.40
Already have an account? Log In

Transcript

Alright guys, so now in this section we're going to start dealing with worksheets. So we're gonna learn how to deal with worksheets and the first thing we're going to learn is actually selecting worksheets. Okay, so when you're selecting worksheets, if you need to select a certain sheet, you actually need to call the worksheets collection, and then tell Excel which sheet you would like to select. So here, I'm going to call the worksheets collection object and then tell the worksheets collection object that I need sheet one from that collection. Okay, as we have described before in the introduction lecture on how the syntax of VBA works. So here there is a collection, you're going to call one member of the collection, which is sheet one, and then you're going to write dot select.

So this is a method select a method. So this We'll make use select sheet one, you can see here I've got two sheets in this workbook, sheet one and sheet two. So I'm going to actually select sheet two here and then I'm going to run this code. And this will select sheet one as you can see here. Okay guys, so now we've seen how we could select a worksheet with the worksheet dot select method. But I actually wanted to show you something else about the Select method as well, which is that there is a parameter in the Select method called replace.

And I'm here on the page for the worksheets dot select method on the Microsoft directory network, which I actually got by googling because highlighting it in the VBA editor and pressing f1 did not get me to that page for some reason, but I just googled worksheet dot select method MSDN and I was able to get that so you can see here there is actually a replace parameter. What this replace parameter does is that it allows us to select several sheets at the same time. So remember guys parameters are like adverbs, they actually describe how the verb is done. So this is actually going to describe how the dot select method, which is considered a verb, you know, as we're mimicking the structure of the English language as we've explained before, so the Replace is going to describe how the dot select method is going to be done.

Okay? So if you put replace equal to false, this means that there's not going to be a replacement when you do another selection. So that means that you're going to select multiple sheets at the same time. But if you put an equals to true, then that means that you will not be selecting multiple sheets at the same time. And it's actually this true is the default value for the Replace parameter. Okay, so let's go back to the Visual Basic environment and see that in action.

Okay, guys, so we're back to the Visual Basic environment. So let's say I want to select shih tzu in addition to sheet one at the same time. So you can actually select two sheets at the same time, you can do it in the Excel environment. If you press control, you know, select one sheet, press control and select the other one, you're going to select two sheets at the same time. So we want to be able to do that in Visual Basic as well. I'm just going to ungroup them to be able to just select sheet one.

So let's say I wanna select sheet two in addition to sheet one. So I'm going to right worksheets, sheet two dot select, and then I'm going to press space and I'm going to write the Replace parameter. So I'm going to write replace, colon equals false. Okay, so the Replace parameter when you set it equal to false, you're going to actually be able to select both of these sheets at the same time. So actually, the first selection is going to happen. And then the second selection will have the parameter replaced equals to false and that means that it's going to In addition to the first selections, if you run that, you can see here the both sheets have been selected at the same time.

So if you actually add a third sheet, you can also select it this way. So you can select the three sheets at the same time. So if you add a line, so I'm just going to copy that and just replace it with sheet three, you can select the third sheet as well. So if you keep adding the selection lines with replace equals to false, you're going to be able to select that particular sheet in addition to the sheets previously selected, okay. And of course, if you put to replace equals to true, then your sheet will not be selected, in addition to the other sheets, but it's actually equals to true by default, if you're going to set it equal to true you're not going to write it right but if you run that with you know without putting the replace or by putting the Replace equals to true, then actually it will just select sheet one and then select sheet two, but when when I select sheet two, it's going to D select sheet one and then was the Lucky Three and when it selects sheet three is going to be select sheet two.

So that means that in the end, you will just have sheet three selected because it's just gonna select sheet one and then select sheet two and then select sheet three, we can run it actually step by step by pressing f8. So here, if you run that line of code is going to select sheet one, and then if you run, the second one is going to select sheet two and then if you run, the third one's just going to select sheet three, so it's just selects them exclusively so the newly selected sheet does not get added to the old sheet. So that's it for the worksheets dot select method. This is one of the basic things that you will need to learn when dealing with sheets, which is how you can select sheets. Okay, thank you very much for watching this video and I'll see you on the next one.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.