+ Reply to Thread
Results 1 to 10 of 10

PointsToScreenPixels giving unexpected results for range width

  1. #1
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    PointsToScreenPixels giving unexpected results for range width

    So I've discovered this today after redoing a task from years ago so having a little play with it. But have noticed something I think might be odd.

    One line of useful code:
    Please Login or Register  to view this content.
    Now if the window sits in one monitor and fully maximized the answer I happen to get is 756 - which seems a fairly plausible answer as the right of column I is a little over half way across my screen.

    Now if I resize the window, but I can styill see all the columns in the range, it turns up as 1045 if I move it right. SO it almost seems to be telling me where the right edge of the range is on the screen rather than telling me the width in pixels. Is this the way it is meant to work or am I missing something? It is driving me round the twist!!

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: PointsToScreenPixels

    That's referencing column L, not column I. Is that it?

    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,908

    Re: PointsToScreenPixels giving unexpected results for range width

    It's telling you where X points from the left hand side of the workbook window is as a screen co-ordinate, therefore it will alter if you move the window.
    Rory

  4. #4
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: PointsToScreenPixels giving unexpected results for range width

    Quote Originally Posted by rorya View Post
    It's telling you where X points from the left hand side of the workbook window is as a screen co-ordinate, therefore it will alter if you move the window.
    I don't think this is right. On a new workbook, Range("A1").Width and Range("Z1").Width both return the same value for me i.e. the width of the range.

    WBD

  5. #5
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,908

    Re: PointsToScreenPixels giving unexpected results for range width

    Huh? I'm talking about ActiveWindow.PointsToScreenPixelsX. If you do:

    Please Login or Register  to view this content.
    and move the window around, you should see different values, which are the X screen position of the first point of the workbook window.

  6. #6
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: PointsToScreenPixels giving unexpected results for range width

    Trying to put those together my understanding was it would give me the width in pixels of A1:L1 (sorry about lower case there).

    If it is the case that it gives me the screen position rather than the pixel width if I take the same number as the left side co-ordinate of a VBA userform when it displays it does not land at the same point ie in this case not where L1 is.. Is it a different measurement for where the userform.left?
    Last edited by malcmail; 01-16-2020 at 12:01 PM.

  7. #7
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: PointsToScreenPixels giving unexpected results for range width

    Quote Originally Posted by rorya View Post
    Huh? I'm talking about ActiveWindow.PointsToScreenPixelsX. If you do:

    Please Login or Register  to view this content.
    and move the window around, you should see different values, which are the X screen position of the first point of the workbook window.
    Yes. Sorry. I was reading your reply incorrectly. What's odd is using this function on something that's returning a width since essentially this is function to return the screen position of a point on the active window. It would make more sense to use:

    Please Login or Register  to view this content.
    That would return the X screen coordinate of the A1 cell. If you want to know the actual width in pixels of the range perhaps you need:

    Please Login or Register  to view this content.
    It's all a bit confusing I guess.

    WBD

  8. #8
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,908

    Re: PointsToScreenPixels giving unexpected results for range width

    If memory serves, the Left property of a userform is given in points, not pixels.

  9. #9
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: PointsToScreenPixels giving unexpected results for range width

    Thanks chaps I'll give this a try. My htought process was that a number could be changed from Points to pixels. WHich it did and gave me the same result as having the range as the object instead. However knowing that it now gives me the spot on the screen of a particular item, and adding in the fact that userforms are set in points I may be able to do it the proper way now!

    Thanks again.

  10. #10
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: PointsToScreenPixels giving unexpected results for range width

    Is there a reverse version of this? SO locate the edge of the screen and convert the pixels of that into points to use to locate the userform correctly?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] call various macro giving unexpected results , need to be run one by one
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2017, 08:51 AM
  2. [SOLVED] Use of ROUND() Giving Unexpected Results
    By PosseJohn in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-13-2015, 07:16 PM
  3. Simple If-Then test giving unexpected results
    By CM1227 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2014, 10:18 AM
  4. Width property of Range object isnt' giving the right results
    By Excel_vba in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-24-2013, 04:27 PM
  5. Formula giving unexpected results
    By johnmerlino in forum Excel General
    Replies: 6
    Last Post: 12-01-2010, 01:20 AM
  6. Autofilter giving unexpected results!
    By Colin Vicary in forum Excel General
    Replies: 3
    Last Post: 09-28-2006, 07:20 AM
  7. Equation giving unexpected results
    By Mike K in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 01-27-2005, 11:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1