What is the syntax to use a With statement?

With <object expression>
End Selection

Use these statements when you need to set many properties for the same object. Improves code readability

‘example without with statement
Selection.HorizontalAlignment = xlCenter
Selection.VerticalAlignment = xlLeft
Selection.Orientation = 0
Selection.WrapText = false

‘example using a with statement
With Selection
 .HorizontalAlignment = xlCenter
 .VerticalAlignment = xlLeft
 .Orientation = 0
 .WrapText = false
End With

Published by



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s