Consulting

Results 1 to 14 of 14

Thread: Get last row of a page

  1. #1
    VBAX Regular
    Joined
    Mar 2013
    Posts
    7
    Location

    Get last row of a page

    After spending countless hours of searching my issue I decided to register at this forum for help.

    I make quotations using excel and with the help of vba I automate some things. Now I want to place the area for signatures on the bottom of the A4-papersize page in excel. However, I cannot figure out how to determine the last row on the page.

    I can figure out the last used row:

    Sheets("Offerte").UsedRange.Rows.Count

    But as there are cells with text wrapping I need the vba code to also return the last row of the page. I was thinking of adjusting the "UsedRange" to firstpage or something like that, but that didn't work either.

    Any suggestions?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I do not understand what you mean by ... cells with text wrapping ...

    Can you clarify, maybe post your workbook?
    ____________________________________________
    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

  3. #3
    VBAX Regular
    Joined
    Mar 2013
    Posts
    7
    Location
    As you can see, the last row on the printable paper is different due to different rowheight (rowheight changes with textwrapping)
    http:\\imgffs.com/i/RnrXl.jpg (swap \\ to //)
    Last edited by kwibis; 03-07-2013 at 02:20 AM.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That doesn't explain anything to me, lastrow has nothing to do with row height.
    ____________________________________________
    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

  5. #5
    VBAX Regular
    Joined
    Mar 2013
    Posts
    7
    Location
    I mean, looking at the dotted line, the last row is 46 (on the left) and 59 on the right.

    http:\\imgffs.com/i/bNmHk.jpg the yellow part needs to be placed at the bottom of the page.
    Last edited by kwibis; 03-07-2013 at 02:36 AM.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I am still not seeing it, there is just one image there, not a left and a right.

    But, if you are worrying about invoices overflowing a page, then you have to manage it. You could do some fancy coding to calculate the height of each row and work out where to split the page, but I would think a better way is to split the invoice into 2, a first single page that summarises the work and the charges, and then a multi-page detailed list of tasks and effort/costs.
    ____________________________________________
    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

  7. #7
    VBAX Regular
    Joined
    Mar 2013
    Posts
    7
    Location
    No that's not the problem. If I would fill cells with text/number and stop at the dotted line (which is the end of the page), then this code:

    Sheets("Offerte").UsedRange.Rows.Count

    would return me a number that is equal to the number of rows that are on one A4-size page. That is the number I need.

    However, now these cells are empty from 47 to 65(http:\\imgffs.com/i/bNmHk.jpg). Thus the code will return 46 instead of 65. Now I want a piece of code that returns the number of rows on the page and not just the used cells.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I think I understand, does this do it

    [vba]
    Sheets("Offerte").Cells(Sheets("Offerte").Rows.Count,"A").End(xlUp).Row[/vba]
    ____________________________________________
    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

  9. #9
    VBAX Regular
    Joined
    Mar 2013
    Posts
    7
    Location
    No, it returns the same as:

    [VBA]Sheets("Offerte").UsedRange.Rows.Count[/VBA]

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Really? Can you post the workbook so I can see why?
    ____________________________________________
    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

  11. #11
    VBAX Regular
    Joined
    Mar 2013
    Posts
    7
    Location
    I made a small workbook. But it has the same on the actual workbook.

    http://db.tt/gmSRdeOI

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You are really confusing me, what is that showing? Both methods show 13, the actual last row. I thought you were saying there were some blank rows at the end that were being counted? Not in this example.
    ____________________________________________
    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

  13. #13
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    I guess he is referring to the last line which "Print Preview" shows. Dotted line (DisplayPageBreaks in VBA) that indicates the extent that will be printed in one page.

    I don't know if it can be accessed via VBA.
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  14. #14
    VBAX Regular
    Joined
    Mar 2013
    Posts
    7
    Location
    Dear shrivallabha,

    That's exactly what I mean. Found a solution on a dutch site.
    [VBA]Sheets("Offerte").HPageBreaks(1).Location.Row[/VBA]
    This gives me the answer I was looking for. Thanks for your time xld!

Posting Permissions

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