I made a routine for converting formulas to code, mainly to replace quotes in the formula.
The problem is when it is too enormous there seems to be a need for carriage return as it looks like it's maxing the immediate window.
I started a carriage return solution (commented out) but it's still not right. It basically spits out code into the immediate window that is a representation of formula of the cursors cell.
So if you put a question mark in front of the immediate window and hit return it should rebuild the formula
Any ideas:
Sub ConvertFormulaToCode()
Dim i As Integer, L1 As Integer
Dim Val1 As String, Chr1 As String, St2 As String, St1 As String, St3 As String
Val1 = Selection.value
St2 = Chr(34) '""
L1 = Len(Val1)
For i = 1 To L1
Chr1 = Mid(Val1, i, 1)
If Chr1 <> Chr(34) Then
St2 = St2 & Chr1
'St3 = St3 & Chr1
Else
St1 = Chr(34) & " & Chr(34) & " & Chr(34)
St2 = St2 & St1 'St2 = St2 & "" & Chr(34) & ""
' St3 = St3 & St1
' If Len(St3) > 140 Then 'add line feed
' St2 = St2 & " &_" & vbCr '& Chr(34)
' St3 = ""
' End If
End If
Next i
St2 = St2 & Chr(34)
Me.Hide
Debug.Print St2
' MsgBox St2
End Sub
The problem is when it is too enormous there seems to be a need for carriage return as it looks like it's maxing the immediate window.
I started a carriage return solution (commented out) but it's still not right. It basically spits out code into the immediate window that is a representation of formula of the cursors cell.
So if you put a question mark in front of the immediate window and hit return it should rebuild the formula
Any ideas:
Sub ConvertFormulaToCode()
Dim i As Integer, L1 As Integer
Dim Val1 As String, Chr1 As String, St2 As String, St1 As String, St3 As String
Val1 = Selection.value
St2 = Chr(34) '""
L1 = Len(Val1)
For i = 1 To L1
Chr1 = Mid(Val1, i, 1)
If Chr1 <> Chr(34) Then
St2 = St2 & Chr1
'St3 = St3 & Chr1
Else
St1 = Chr(34) & " & Chr(34) & " & Chr(34)
St2 = St2 & St1 'St2 = St2 & "" & Chr(34) & ""
' St3 = St3 & St1
' If Len(St3) > 140 Then 'add line feed
' St2 = St2 & " &_" & vbCr '& Chr(34)
' St3 = ""
' End If
End If
Next i
St2 = St2 & Chr(34)
Me.Hide
Debug.Print St2
' MsgBox St2
End Sub