Using With End With

If you need to set a number of properties for an object, your code is easier to read and faster running if you use the With-End With construct. The following code doesn't use With-End With:

Selection.HorizontalAlignment = xlCenter Selection.VerticalAlignment = xlCenter Selection.WrapText = True Selection.Orientation = 0 Selection.ShrinkToFit = False Selection.MergeCells = False

The next code performs the same action but is rewritten to use With-End With:

With Selection


= xlCenter

.VerticalAlignment =


.WrapText = True

.Orientation = 0

.ShrinkToFit = False

.MergeCells = False

End With

0 0

Post a comment