please explain line of code

hansclark

New Member
Joined
Aug 1, 2005
Messages
38
I'm writing a print setup macro in which I need to determine what the current top margin is. I searched VBA help and found the following snippet of code in the entry for TopMargin Property.

Code:
marginInches = ActiveSheet.PageSetup.TopMargin / _
    Application.InchesToPoints(1)

The code worked just fine and returned the correct margin value when I tested it.

My question is how/why did it work? I have never come across syntax like this. In particular I am not sure what the "/" character is for. Can anyone translate the code above into plain English?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
As far as I can see the / is just the mathematical division operator.

The line of code might look a little confusing because of the use of the line extension character _.

It could be written like this.
Code:
marginInches = ActiveSheet.PageSetup.TopMargin / Application.InchesToPoints(1)

Whoops, that should be all on one line.:oops:
 
Upvote 0
It is dividing

ActiveSheet.PageSetup.TopMargin

by Application.InchesToPoints(1)

in order to get the margin in inches instead of points.
 
Upvote 0
ok I think I understand now. it didn't click with me at first that this was a conversion.

just to clarify...this is like converting minutes to hours, e.g 30 minutes divided by 60 equals 0.5 hours.

thanks for the quick replies.
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,243
Members
449,075
Latest member
staticfluids

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