strange With code

dennisli

Well-known Member
Joined
Feb 20, 2004
Messages
1,070
Good afternoon,
I got this code from someone else. Is this a typical VBA code? If then, what does this code mean?
Thanks.

Code:
    With ActiveCell
      EnterCol 1, "Policy", "Number", "=LossIn!E2", xlCenter, "", 12
    End With
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
The With isn't doing anything so I don't see why it's there but it's not really doing any harm.

Perhaps just something left over from earlier code?

The rest of the code seems fine - it's calling a sub/function with all those arguments.
 
Upvote 0
Yes and No

It's very common to use With..
But it's not used correctly in that example.
The With is completely useless in that example.


When you use With, you are referring to some object.
Usually a range like ("A1:A10") or a Sheet or Book.
Then in subsequent code (before the End With), you refer to that object with a period.

Like
Code:
With Range("A1:A10")
    .Interior.ColorIndex = 3
    .Font.Bold = True
End With

It's usefull when you need to make multiple commands on the same object.
Makes it easier, you don't have to rewrite the same object over and over again.


But your example does not use the period in to refer to the object referenced (ActiveCell)


Hope that helps.
 
Upvote 0
The sub being called within the code might actually be a replacement for a long series of statements that were used before.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,712
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top