Consulting

Results 1 to 13 of 13

Thread: Solved: Calculating Height of a range

  1. #1
    VBAX Regular
    Joined
    Jun 2008
    Location
    California
    Posts
    89
    Location

    Red face Solved: Calculating Height of a range

    Hi,

    I need to calculate the height of a Range of rows. Some rows may be texted wrapped and therefore taller than others. I will be pasting each range I create into Word and will need to know if two ranges can fit on one page or will I need insert a page break and then dump the Column headers and other data that proceeds each range that starts a new Page.

    I will be using the following to generate my ranges.
    [vba] ActiveCell.Offset(1,-14)
    Dim rngT20 As Range
    Dim rngD20 As Range
    Dim rngTD20 As Range
    Set rngT20 = Selection
    ActiveCell.Offset(6, 14).Select
    Set rngD20 = Selection
    Set rngTD20 = Range(rngT20, rngD20)
    [/vba]
    Also,
    Could someone breakdown the For...Next statement? I see them alot and not sure how to use them...also why does everyone always seem to use j or i when writing the For...Next statement?

  2. #2
    VBAX Tutor Mavyak's Avatar
    Joined
    Jul 2008
    Posts
    204
    Location
    [VBA]rngTD20.Height[/VBA]

    That will get you the height of the range. I believe the value returned is in "twips", which is a printing measurement. To get inches, divide by 1440.

  3. #3
    VBAX Regular
    Joined
    Jun 2008
    Location
    California
    Posts
    89
    Location
    Thank you...

  4. #4
    VBAX Regular
    Joined
    Jul 2008
    Location
    Cincinnati, OH
    Posts
    86
    Location
    "That will get you the height of the range. I believe the value returned is in "twips", which is a printing measurement. To get inches, divide by 1440."

    Am pretty sure that height is in points??? 72 points per inch.

  5. #5
    VBAX Tutor Mavyak's Avatar
    Joined
    Jul 2008
    Posts
    204
    Location
    I couldn't find a unit of measurement on the help page so I assumed twips. Thanks for the correction!

  6. #6
    VBAX Contributor
    Joined
    Jun 2007
    Posts
    150
    Location
    Yep, everything in Excel is measured in Points.
    From Wikipedia:
    In typography, a point is the smallest unit of measure, being a subdivision of the larger pica. It is commonly abbreviated as pt. The traditional printer's point, from the era of hot metal typesetting and presswork, varied between 0.18 and 0.4 mm depending on various definitions of the foot.
    Today, the traditional point has been supplanted by the desktop publishing point (also called the PostScript point), which has been rounded to an even 72 points to the inch.
    (1 point = 127360 mm = 352.7 ?m) In either system, there are 12 points to the pica.
    This is a holdover from the fact that Excel was originally a Mac product, and the Mac was very geared towards desktop publishing.

  7. #7
    VBAX Contributor
    Joined
    Oct 2004
    Posts
    159
    Location
    The row height is measured in points (1pt = 1/72 inch or about 1/28 centimeters). A point is a "unit of measure referring to the height of a printed character" (quoting from the VBA help file for the RowHeight property).

  8. #8
    VBAX Regular
    Joined
    Jun 2008
    Location
    California
    Posts
    89
    Location
    Thanks!!!!! What's confusing me is let's say I change a row's height to 19. When I use the formula above the value is 18.75. Then If I change the row height to 18.75 it then says 18.75 and 20 rowheight is 19.5...weird.

    Can any of you also explain the whole For...Next statement. That too has me a little confused.

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It works in multiples of .75, so you cannot set it to 19. You might think you di, but Excel changed it.

    Anf what For ... Next loop are you referring to.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  10. #10
    VBAX Regular
    Joined
    Jun 2008
    Location
    California
    Posts
    89
    Location
    Ahhhhh thanks....

    For...Next in General.... When to use it and how to use it... they confuse me because it looks like they are doing increments but I don't see how...and it's not always clear when it stops like say a Do...Loop Until

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    They iterate through a collection, processing each item in the collections in the order they are located within the collection, such as Worksheets, Workbooks, cells etc.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  12. #12
    VBAX Regular
    Joined
    Jun 2008
    Location
    California
    Posts
    89
    Location
    Hi,

    Can you go into a little more detail than that... examples are nice...lol
    Please please please...
    I'm not even sure when to use them

  13. #13
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It is all explained in VBA help. Just lookup For, and For ... Next will be there
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •