Assigning string "AJ" to a variable in VBA is not working. why ?

Navin8211

New Member
Joined
Aug 11, 2023
Messages
1
Office Version
  1. 2013
Platform
  1. Windows
Hello, I am trying to assign a strong "AJ" to a variable in VBA. After executing the code, I am getting an empty variable.

I am assigning like below,
Var1="AJ"

This AJ is actually referring to 'AJ' column in another tab of the Excel sheet. Please do provide some insights on how to tackle this problem. Thank you in advance.
 
Hey, you helped, in the original code our variable had all lower case letters in the variable name.
I changed it from lookupvalue to lookupValue and its working fine.

Very Very odd.
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Change your code to use lower case in the variable. When I did it using your code i get the result we are seeing.

Sub test()
Dim var1 As String
var1 = "AJ"
MsgBox var1
var1 = Cells(1, 36).Address
MsgBox var1

End Sub
 
Upvote 0
Change your code to use lower case in the variable. When I did it using your code i get the result we are seeing.

Sub test()
Dim var1 As String
var1 = "AJ"
MsgBox var1
var1 = Cells(1, 36).Address
MsgBox var1

End Sub
I see no difference with case in the variable name or the string being assigned to it.
 
Upvote 0
Change your code to use lower case in the variable. When I did it using your code i get the result we are seeing.

Sub test()
Dim var1 As String
var1 = "AJ"
MsgBox var1
var1 = Cells(1, 36).Address
MsgBox var1

End Sub
Very VERY ODD the only difference in this working or not is having using Var1 vs var1
 
Upvote 0
I see no difference with case in the variable name or the string being assigned to it.
I am not sure what you are looking at, We are running this on 3 separate computers. We all get different results for Var1 vs var1. Again we see it in all cases in DEBUG.PRINT and Locals, but it only shows up in hover when the capital letter is used in variable name. Likewise our automated formulas work and are able to see that value.

Maybe MS resolved this and our version of Excel 365 is different than yours?
 
Upvote 0
I am not sure what you are looking at, We are running this on 3 separate computers. We all get different results for Var1 vs var1. Again we see it in all cases in DEBUG.PRINT and Locals, but it only shows up in hover when the capital letter is used in variable name. Likewise our automated formulas work and are able to see that value.

Maybe MS resolved this and our version of Excel 365 is different than yours?
Quite possibly. I don't know if there is anyway to tell why it doesn't like the name. Is it possibly a language issue? The only reason I ask is because different excel languages might have different reserved names.
 
Upvote 0
Quite possibly. I don't know if there is anyway to tell why it doesn't like the name. Is it possibly a language issue? The only reason I ask is because different excel languages might have different reserved names.
Thats a good thought, but it doesnt seem to matter what name I use for the variable, If theres no capital letter in the varible name it fails. . . I have tried several random names even "bob" and "Bob". lol
The important thing is its working . . . and we are going to make sure we start using at least 1 capital letter in our naming.
Thank you
Dennis
 
Upvote 0
Do you use the Option Explicit declaration? It should be used to help with variable Case sensitivity.
 
Upvote 0
I will toss this out there, because I have seen something like this happen before.
Do you happen to have any Global Variables, Procedures Names, or Function Names in your VBA project named "Var1"?
That could cause interference and unexpected results.

An easy way to find out is to go into VBA and bring up the Search box and search the ENTIRE Project for "Var1", and cycle through the Search box to see all the different places it shows up.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top