Using With and End With When Referring to an Object
Using With and End With When Referring to an Object:-
In each subsequent line, you could leave off the name of the chart and begin the line with a period. You would end the block of code with an End With statement. This is faster to write than typing the complete object name multiple times, and it executes faster because Excel only has to figure out what WS.ChartObjects(“Chart1”) means once. The following code uses the With syntax while setting five properties:
Dim WS as Worksheet
Set WS = ThisWorkbook.Worksheets(“Income Statement”)
With WS.ChartObjects(“Chart1”)
.Chart.SetSourceData Source: = WS.Range(“A1:E4”)
.Left = 10
.Top = 30
.Width = 300
.Height = 200
End With
|