When I compare the value of a cell that contains ?
to a variable, it always returns true. Is there any way I can prevent this? Here is my current code:
'Option Explicit
Dim hws As Worksheet
Set hws = ActiveSheet
Dim rng As Range, rng2 As Range
Dim letters(2, 2)
alpha = Range("CipherTable").Value
For x = 1 To 7
For y = 1 To 7
If alpha(x, y) = rng.Cells(i, j + 1).Value Then
letters(2, 1) = x
letters(2, 2) = y
End If
Next y
Next x
alpha, by the way, looks like this:
A B C D E F G
H I J K L M N
O P Q R S T U
V W X Y Z 1 2
3 4 5 6 7 8 9
0 ; : ' " . ,
( ) _ - + ? !
This always returns A
, which is in alpha(1,1). Come to think of it, since they each go to seven, I don't know why it don't come back with !
. How can I get around this and make it return true only when it actually matches?
I tried the following, and got the expected result (it was able to find the question mark):
(1) Created CipherTable range in worksheet, as above;
(2) Created a function QM similar to code above;
(3) Entered a formula in the style of =QM(cell-ref).
It worked fine. Function QM:
====
I also tried something more direct, and got the response expected:
As far as I understand you want to create a substitution algorithm. If there is no specific reason to use a two dimensional cipher table I would rather use a one dimensional approach like the following:
calling this function with
results in
THEQUICKBROWN(?)FOX123+-
(because we don't allow blanks inModel
orSubst
)Now change
Subst
toresult is
4,_73.+'?6910GBF)9ZWVUCD
if you feed the above into the cipher function, you end up again with
THEQUICKBROWN(?)FOX123+-
as you would expect from a symetrical substitution.