Whats wrong with my code?I want a code that shifts a word to an amount (dog to fqi)and the input in an input box.The ouput in a 20 column by n row array.And z if shifted by 2 would be b.Thanks

Function ShiftCipher(text)
        shiftamount = InputBox("Input how many numbers to shift by")
        text = InputBox("Input text")
        tempText = LCase(x)
    
        Row = 1
        Column = 1
        Worksheets("Encrypt").Cells(Row, Column) = Encrypt(shift, i, 1)
        Column = Column + 1
        If Column > 20 Then
        Row = Row + 1
        Column = 1
        End If
        Next i
        
        Select Case letter
        Case "a"
                letter = Chr((0 + shiftamount) Mod (26) + 97)
        Case "b"
                letter = Chr((1 + shiftamount) Mod (26) + 97)
        Case "c"
                letter = Chr((2 + shiftamount) Mod (26) + 97)
        Case "d"
                letter = Chr((3 + shiftamount) Mod (26) + 97)
        Case "e"
                letter = Chr((4 + shiftamount) Mod (26) + 97)
        Case "f"
                letter = Chr((5 + shiftamount) Mod (26) + 97)
        Case "g"
                letter = Chr((6 + shiftamount) Mod (26) + 97)
        Case "h"
                letter = Chr((7 + shiftamount) Mod (26) + 97)
        Case "i"
                letter = Chr((8 + shiftamount) Mod (26) + 97)
        Case "j"
                letter = Chr((9 + shiftamount) Mod (26) + 97)
        Case "k"
                letter = Chr((10 + shiftamount) Mod (26) + 97)
        Case "l"
                letter = Chr((11 + shiftamount) Mod (26) + 97)
        Case "m"
                letter = Chr((12 + shiftamount) Mod (26) + 97)
        Case "n"
                letter = Chr((13 + shiftamount) Mod (26) + 97)
        Case "o"
                letter = Chr((14 + shiftamount) Mod (26) + 97)
        Case "p"
                 letter = Chr((15 + shiftamount) Mod (26) + 97)
        Case "q"
                 letter = Chr((16 + shiftamount) Mod (26) + 97)
        Case "r"
                 letter = Chr((17 + shiftamount) Mod (26) + 97)
        Case "s"
                 letter = Chr((18 + shiftamount) Mod (26) + 97)
        Case "t"
                 letter = Chr((19 + shiftamount) Mod (26) + 97)
        Case "u"
                 letter = Chr((20 + shiftamount) Mod (26) + 97)
        Case "v"
                 letter = Chr((21 + shiftamount) Mod (26) + 97)
        Case "w"
                 letter = Chr((22 + shiftamount) Mod (26) + 97)
        Case "x"
                 letter = Chr((23 + shiftamount) Mod (26) + 97)
        Case "y"
                 letter = Chr((24 + shiftamount) Mod (26) + 97)
        Case "z"
                letter = Chr((25 + shiftamount) Mod (26) + 97)
     End Function
        End Select

Just use the ASCII values Chart for the characters. I don't know why you're using all those Mod functions? ASCII values for the UpperCase letters run from 64- 90, lowercase from 97 - 122.

You'll have to write code to deal with any shifts that throw you over the limits (90 or 122). But you can add 2 directly to the value of the Ascii Value to obtain the shift value.

For instance the ASCII value of 'a' is 97. Add 2 it would be 99. chr$(99) would be 'c'
There are UCase and LCase functions to convert Upper to Lower and Lower to Upper case.

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.