Hejhej,
I try to compare two values for equality. While I definitly compare the same values, it fails when the left (or right function for that matter) is involved.
I created a minimal example to demonstrate my problem. I have also experiences a lot with adding ".value" and some other things, nothing seemed to work...
Can someone explain to me why the first if-clause is not true and the second is? It is the same value! Why doesn't it work?
(I expect "yes" to be in both cells 5, 1 and 6, 1).
Thanks!
EDIT: Tested in Excel 2001 and 2007.
I try to compare two values for equality. While I definitly compare the same values, it fails when the left (or right function for that matter) is involved.
I created a minimal example to demonstrate my problem. I have also experiences a lot with adding ".value" and some other things, nothing seemed to work...
Code:
Option Explicit
Dim tmp As String
Sub testleft()
Cells(1, 1) = 123456
Cells(1, 3) = 123
tmp = Left(Cells(1, 1), 3)
' not equal:
If Cells(1, 3) = Left(Cells(1, 1), 3) Then
Cells(5, 1) = "yes"
End If
' equal:
If Cells(1, 3) = tmp Then
Cells(6, 1) = "yes"
End If
End Sub
(I expect "yes" to be in both cells 5, 1 and 6, 1).
Thanks!
EDIT: Tested in Excel 2001 and 2007.
Last edited: