"String" manipulation for a Case clause
It is a pleasure to see how well a professional can make VBA concise and efficient!
Thanks Jim
"Jim Cone" wrote:
With a 2 dimensional array, you can only resize & preserve the second dimension.
So with. arr(1 to 100, 1 to 3) - you cannot change the 1 to 100 part.
'---
Sub FigureItOut_R1()
Dim N As Long
Dim M As Long
Dim x As Long
Dim i As Long
Dim lngLength As Long
Dim strWhat As String
Dim strGiven As String
Dim vThings As Variant
Dim strArr() As String
ReDim strArr(1 To 100)
strGiven = _
"-9'Min. Int.'!F26-'Min.-7 Int.'!F31+28038.66^35+[C:\123]'Clos-6ing'!E3^1"
vThings = Array("-", "+", "^", "\", "/", "*")
strGiven = strGiven & " "
lngLength = Len(strGiven)
M = 0
For N = 0 To UBound(vThings)
Do
M = InStr(M + 1, strGiven, vThings(N), vbBinaryCompare)
If M 0 Then
If Mid$(strGiven, M + 1, 1) Like "#" Then
For i = M + 2 To lngLength
If Not Mid(strGiven, i, 1) Like "[0-9.]" Then
' strWhat = Mid$(strGiven, M + 1, i - (M + 1))
strWhat = Mid$(strGiven, M, i - M) & Chr$(10) & _
"Len: " & i - M & Chr$(10) & "Pos: " & M
Exit For
End If
Next
x = x + 1
strArr(x) = strWhat
End If
Else
Exit Do
End If
Loop
Next
ReDim Preserve strArr(1 To x)
Range("A1", Cells(1, x)).Value = strArr()
End Sub
|