Results 1 to 13 of 13

Thread: A really, really strange Excel problem

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    A really, really strange Excel problem

    Create this sub, put a breakpoint on the End Sub line and execute it
    Code:
    Sub test()
    Dim strCol As String
    strCol = "AJ"
    'MsgBox strCol
    End Sub
    In my Excel if I check at the breakpoint what strCol is, it shows up as blank! However if I uncomment the MsgBox line the Msgbox shows AJ.

    Note that if I change strCol to "XX" or any other value (as far as I know), strCol becomes XX with or without the MsgBox.

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,632

    Re: A really, really strange Excel problem

    I don't have convenient access to anything newer than Office 2003 at the moment, but I'm unable to reproduce the issue in Excel 2003. Breakpoint set at End Sub, value of strCol when ran = "AJ" when code paused at the breakpoint.
    Last edited by OptionBase1; Feb 24th, 2023 at 07:35 PM.

  3. #3

  4. #4
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,632

    Re: A really, really strange Excel problem

    Amazing. I can't imagine how some strangely specific bug like that makes its way into production code.

  5. #5
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,632

    Re: A really, really strange Excel problem

    Out of curiosity, I tried it in Excel 97 SR2-B and Excel XP SP3 and the issue doesn't happen on them either.

  6. #6

  7. #7
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526

    Re: A really, really strange Excel problem

    Works OK on my Office 2016.

  8. #8
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,264

    Re: A really, really strange Excel problem

    Is the same issue on O365.
    Tooltip doesn't show Value.
    Watch-Window works, though.

    Begs the Question, what's so special about "AJ" to confuse the Tooltip
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  9. #9
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,264

    Re: A really, really strange Excel problem

    Bugger it!
    Just ran afoul of this in my own code.
    I have a lookup-worksheet "Config" where i keep column-describers ("SalesPrice is in Column AJ") Column A="SalesPrice", ColumnB="AJ"
    where at runtime my code fishes the column-letters from that sheet.

    And i got permanently Error 1004 until i remembered this thread.

    Blast it!
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  10. #10
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526

    Re: A really, really strange Excel problem

    I have not had this error occur on my systems.

    However, I wonder what would happen if you changed the code to:

    Code:
    Sub test()
    Dim strCol As String
    strCol = "A" & "J"
    'MsgBox strCol
    End Sub

  11. #11
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,264

    Re: A really, really strange Excel problem

    Jdc, the bug is with the tooltip, not the value and the variable itself.
    i thought i got that error because my lookup function was faulty. The error was produced somewhere else, but since i didn’t see the value in the tooltip i thought it was empty, and i was chasing the wrong cat-tail
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  12. #12
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526

    Re: A really, really strange Excel problem

    Zvoni,

    Thanks. Now I understand what is happening. I retested it on my computers, and it does not matter what you set strCol to, "AJ" or "XX", it shows as "" in the ToolTip if you put the break point on that line. If you put the break point on the End Sub, it works OK. You cannot put a break point on the commented out MsgBox, but you can if it is not commented. I usually avoid this issue by inserting Stop statements into the code where I want to check something.

  13. #13
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,264

    Re: A really, really strange Excel problem

    Quote Originally Posted by jdc2000 View Post
    Zvoni,

    Thanks. Now I understand what is happening. I retested it on my computers, and it does not matter what you set strCol to, "AJ" or "XX", it shows as "" in the ToolTip if you put the break point on that line. If you put the break point on the End Sub, it works OK. You cannot put a break point on the commented out MsgBox, but you can if it is not commented. I usually avoid this issue by inserting Stop statements into the code where I want to check something.
    Funny enough, in VBA i use a lot of „old school“ variable checking issuing Debug.Print‘s
    i take it out of production code with a global const.
    something along the lines
    Code:
    Public Const DO_DEBUG As Boolean = True
    
    
    ‘Somewhere else
    If DO_DEBUG Then Debug.Print SomeVariable
    When the code goes live i just set the constant to False
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

Posting Permissions

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



Click Here to Expand Forum to Full Width