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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,351
Office Version
  1. 365
Platform
  1. Windows
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:
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
It is dividing

ActiveSheet.PageSetup.TopMargin

by Application.InchesToPoints(1)

in order to get the margin in inches instead of points.
 

hansclark

New Member
Joined
Aug 1, 2005
Messages
38
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.
 

Forum statistics

Threads
1,170,932
Messages
5,872,779
Members
432,944
Latest member
mj02

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
Top