Option Explicit
Dim shiftVal() As Integer
Public Sub Decode()
Dim ans As String, i As Integer, j As Integer, ctr As Integer
Dim cl As Range
On Error GoTo escape
'determine encoding values
ans = InputBox("Hi")
ReDim shiftVal(1 To 100 * Len(ans))
ctr = 0
For i = 1 To 100
For j = 1 To Len(ans)
ctr = ctr + 1
shiftVal(ctr) = -4 + (Asc(Mid(ans, j, 1)) Mod 10)
Next j
Next i
'apply code
For Each cl In Sheets("X").UsedRange
If Not IsEmpty(cl) Then
If Len(cl) > 100 * Len(ans) Then GoTo escape
cl = DecodeString(cl.Value)
End If
Next cl
Exit Sub
escape:
MsgBox "Unsuccessful"
End Sub
Public Function DecodeString(str As String) As String
Dim i As Integer, ch As String, newStr As String
On Error GoTo escape
newStr = ""
For i = 1 To Len(str)
ch = Mid(str, i, 1)
newStr = newStr & Chr(Asc(ch) - shiftVal(i))
Next i
DecodeString = newStr
Exit Function
escape:
DecodeString = "Error"
MsgBox "Unsuccessful"
End Function