# How do I stop my variable turning boolean



## grumpyoldman (Dec 27, 2022)

I have a VBA running in excel sometimes it turn T from 1 to true and then fails because in cannot look into Cell "True"


----------



## shinigamilight (Dec 27, 2022)

```
dim k as long
dim k as single 
dim k as double
dim k as integer
```
these all can only contain numerical values.


----------



## grumpyoldman (Dec 27, 2022)

Dim t As Integer

later on in my vba it still turns to True
M$(LV, t, TT, 3) = Worksheets("Match").Cells(120 + 7, 1 + (t = 1))


----------



## jdellasala (Dec 27, 2022)

grumpyoldman said:


> Dim t As Integer
> 
> later on in my vba it still turns to True
> M$(LV, t, TT, 3) = Worksheets("Match").Cells(120 + 7, 1 + (t = 1))


I am not strong on VBA at all, however if you're getting a TRUE/FALSE result, it means you're making an equivalence equation when you actually want to assign a value to a variable.
The equation above appears to be an equivalence, not an assignment. As best as I know you can't assign a value to multiple variables. There are multiple variables to the left of the equal sign, so the formula M$(LV, t, TT, 3) is going to be evaluated, and compared to the value on the right side of the equal sign and return TRUE or FALSE. There are no other possibilities there.


----------



## grumpyoldman (Dec 28, 2022)

Thank you jdellasla you are most likely right, I am converting an old ZX81 game to Excel. I have omitted the second "=" sign and it seems to work now. I wanted to keep it as near to the original as Possible I guess some things get lost in Translation. Anyway thank you all for answering.
​​


----------



## Fluff (Dec 28, 2022)

The part in red is testing to see if t=1 & will return true/false as a result

```
M$(LV, t, TT, 3) = Worksheets("Match").Cells(120 + 7, 1 + (t = 1))
```
If t does = 1 then the 1+(t=1) will return 0 otherwise it will return 1


----------



## grumpyoldman (Dec 28, 2022)

for some unexplained reason every now and again it returned true, I have no idea why!!


----------



## Fluff (Dec 28, 2022)

Maybe you had true in the cell being referenced.
If t was = 1 then you would get an error.


----------

