The With Statement

Excel VBA for Beginners 8- Must know Excel Logic
3 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
€86.76
List Price:  €121.48
You save:  €34.71
£74.67
List Price:  £104.54
You save:  £29.87
CA$138.09
List Price:  CA$193.33
You save:  CA$55.24
A$155.63
List Price:  A$217.90
You save:  A$62.26
S$130.40
List Price:  S$182.57
You save:  S$52.16
HK$775.99
List Price:  HK$1,086.42
You save:  HK$310.43
CHF 80.70
List Price:  CHF 112.99
You save:  CHF 32.28
NOK kr1,041.35
List Price:  NOK kr1,457.94
You save:  NOK kr416.58
DKK kr647.86
List Price:  DKK kr907.02
You save:  DKK kr259.16
NZ$166.43
List Price:  NZ$233.01
You save:  NZ$66.58
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳12,143.18
List Price:  ৳17,000.94
You save:  ৳4,857.76
₹8,513.11
List Price:  ₹11,918.70
You save:  ₹3,405.58
RM436.95
List Price:  RM611.75
You save:  RM174.80
₦160,437.95
List Price:  ₦224,619.55
You save:  ₦64,181.60
₨28,143.44
List Price:  ₨39,401.94
You save:  ₨11,258.50
฿3,308.36
List Price:  ฿4,631.84
You save:  ฿1,323.48
₺3,819.79
List Price:  ₺5,347.87
You save:  ₺1,528.07
B$593.14
List Price:  B$830.42
You save:  B$237.28
R1,868.36
List Price:  R2,615.78
You save:  R747.42
Лв172.12
List Price:  Лв240.97
You save:  Лв68.85
₩141,905.31
List Price:  ₩198,673.11
You save:  ₩56,767.80
₪368.88
List Price:  ₪516.44
You save:  ₪147.56
₱5,656.38
List Price:  ₱7,919.16
You save:  ₱2,262.78
¥14,097.29
List Price:  ¥19,736.77
You save:  ¥5,639.48
MX$1,965.48
List Price:  MX$2,751.75
You save:  MX$786.27
QR364.29
List Price:  QR510.02
You save:  QR145.73
P1,377.36
List Price:  P1,928.36
You save:  P551
KSh12,961.55
List Price:  KSh18,146.69
You save:  KSh5,185.13
E£5,044.66
List Price:  E£7,062.73
You save:  E£2,018.06
ብር13,323.32
List Price:  ብር18,653.18
You save:  ብር5,329.86
Kz91,190.88
List Price:  Kz127,670.88
You save:  Kz36,480
CLP$96,756.32
List Price:  CLP$135,462.72
You save:  CLP$38,706.40
CN¥728.52
List Price:  CN¥1,019.96
You save:  CN¥291.44
RD$6,027.39
List Price:  RD$8,438.59
You save:  RD$2,411.20
DA13,263.54
List Price:  DA18,569.48
You save:  DA5,305.94
FJ$228.55
List Price:  FJ$319.98
You save:  FJ$91.43
Q770.07
List Price:  Q1,078.13
You save:  Q308.06
GY$20,943.20
List Price:  GY$29,321.32
You save:  GY$8,378.12
ISK kr12,590.74
List Price:  ISK kr17,627.54
You save:  ISK kr5,036.80
DH924.24
List Price:  DH1,293.98
You save:  DH369.73
L1,729.79
List Price:  L2,421.77
You save:  L691.98
ден5,365.75
List Price:  ден7,512.27
You save:  ден2,146.51
MOP$799.27
List Price:  MOP$1,119.02
You save:  MOP$319.74
N$1,868.61
List Price:  N$2,616.13
You save:  N$747.52
C$3,677.16
List Price:  C$5,148.17
You save:  C$1,471.01
रु13,625.88
List Price:  रु19,076.78
You save:  रु5,450.89
S/374.14
List Price:  S/523.81
You save:  S/149.67
K413.25
List Price:  K578.58
You save:  K165.32
SAR375.18
List Price:  SAR525.27
You save:  SAR150.08
ZK2,850.34
List Price:  ZK3,990.59
You save:  ZK1,140.25
L431.61
List Price:  L604.28
You save:  L172.66
Kč2,173.88
List Price:  Kč3,043.52
You save:  Kč869.64
Ft35,338.69
List Price:  Ft49,475.58
You save:  Ft14,136.89
SEK kr951.25
List Price:  SEK kr1,331.79
You save:  SEK kr380.53
ARS$112,282.22
List Price:  ARS$157,199.61
You save:  ARS$44,917.38
Bs691.72
List Price:  Bs968.44
You save:  Bs276.71
COP$424,576.35
List Price:  COP$594,423.88
You save:  COP$169,847.52
₡50,228.06
List Price:  ₡70,321.30
You save:  ₡20,093.23
L2,586.88
List Price:  L3,621.73
You save:  L1,034.85
₲799,721.01
List Price:  ₲1,119,641.41
You save:  ₲319,920.40
$U4,234.41
List Price:  $U5,928.35
You save:  $U1,693.93
zł371.12
List Price:  zł519.58
You save:  zł148.46
Already have an account? Log In

Transcript

Hey guys, welcome back. So in this video we're going to discuss the width statement in Excel VBA. So the width statement in Excel VBA is a statement that allows you to save a bit of space and a bit of code typing or keystrokes on your keyboard. It doesn't give you any extra functionality so it's not like if you don't use it you will be missing anything is just save some time and keystrokes. So basically, the width statement allows you to apply different methods and properties to a certain object that you choose to use with the width statement. So let's say here I'm going to add the value of 52 range a one to 271 and then I'm going to make the font bold.

I'm going to make it Italic and I'm going to make it size to be 12. So if you run this macro that is gonna hop in here in cell A one you can actually do all these actions using the width statement as well. So the structure of the width is basically with and then range a one. So we want to do the same thing using the width statement. So with range a one and don't forget to write the end width, because this marks the end of the actions that you're going to do to your object. So with that particular object, you're going to start writing what you want to do with it.

Okay, so we're going to start writing the methods and properties that you want to take actions with. So basically, dot value. And you can see here that the IntelliSense for VBA is working the autocomplete feature in VBA is working because it's understanding that this is a width statement. I'm trying to do stuff to the objects. So dot value equals 50, and then dot font dot bold equals true and then dot font dot italic equals true as well. And then dot font dot size equals 12.

So this with statement is going to accomplish the same thing as these statements. And notice here that I've actually indented my code a bit. So I've indented what's between the width and the end width by actually hitting tab on my keyboard. So if I actually press enter here on the beginning of the line, if I want to indent that line a bit, I press tab on my keyboard, okay, and I'm just indenting it for readability. So this does not affect the execution of your code or anything is just affects the readability. It makes it more readable.

It gives you the sense or the feeling that these actions here that I'm taking on that object are between this width and this end width statement. They are enclosed inside it. So it just makes your code more readable doesn't affect The execution of your code. So I'm actually gonna highlight the previous code, and I'm actually gonna comment that code. So I'm gonna comment all the block of code so that it wouldn't be executed. And then I'm actually gonna delete the contents of that.

So I'm going to clear everything, so clear value on formatting and everything. And then if I execute that code, you can see here that we've done the same thing, basically. So this width statement allows you to do the same thing as the above four lines of code, except that you do it with less keystrokes. So if you don't use the with statement, you will not be missing any functionality. It's just that you're going to save some keystrokes when you use it. So that's it guys for the width statement.

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.