|
-
Feb 24th, 2023, 06:56 PM
#1
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.
Last edited by MartinLiss; Feb 24th, 2023 at 07:26 PM.
-
Feb 24th, 2023, 07:15 PM
#2
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.
-
Feb 24th, 2023, 07:30 PM
#3
Re: A really, really strange Excel problem
-
Feb 24th, 2023, 07:43 PM
#4
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.
-
Feb 24th, 2023, 07:48 PM
#5
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.
-
Feb 24th, 2023, 07:52 PM
#6
Re: A really, really strange Excel problem
-
Feb 27th, 2023, 10:50 AM
#7
Re: A really, really strange Excel problem
Works OK on my Office 2016.
-
Feb 28th, 2023, 06:22 AM
#8
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
-
Mar 29th, 2023, 09:09 AM
#9
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
-
Mar 29th, 2023, 10:19 AM
#10
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
-
Mar 29th, 2023, 11:22 AM
#11
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
-
Mar 29th, 2023, 02:58 PM
#12
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.
-
Mar 29th, 2023, 04:56 PM
#13
Re: A really, really strange Excel problem
 Originally Posted by jdc2000
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|