OK got this working code for all below
Code:
'cuts up the string into an array depending on the number of characters you want
Function sliceCharByNum(FullString As Variant, NumberOfCharacters As Long, Descending As Boolean) As String()
If NumberOfCharacters <= 0 Then
Dim arrEmptyNum() As String
ReDim arrEmptyNum(0 To 0) As String
arrEmptyNum(0) = FullString
sliceCharByNum = arrEmptyNum()
Exit Function
End If
If Len(FullString) = 0 Then
Dim arrEmpty() As String
ReDim arrEmpty(0 To 0) As String
arrEmpty(0) = FullString
sliceCharByNum = arrEmpty()
Exit Function
Else
Dim SliceByNum As Long, CurrentVal As Long, i As Long
Dim strText As String, strImportedText As String
Dim arr() As String
ReDim arr(0 To 0) As String
'NumFrom = Len(FullString)
SliceByNum = IIf(NumberOfCharacters = 0, 1, NumberOfCharacters)
strImportedText = Nz(FullString, "")
CurrentVal = Len(strImportedText)
i = 0
Do Until strImportedText = ""
If Len(strImportedText) < NumberOfCharacters Then
ReDim Preserve arr(0 To i) As String
arr(i) = strImportedText
strImportedText = ""
Else
strText = ""
strText = Left(strImportedText, NumberOfCharacters)
CurrentVal = CurrentVal - NumberOfCharacters
strImportedText = Right(strImportedText, CurrentVal)
ReDim Preserve arr(0 To i) As String
arr(i) = strText
i = i + 1
End If
Loop
End If
If Descending = True Then
Dim Temp As Variant
Dim Ndx As Long
Dim Ndx2 As Long
Ndx2 = UBound(arr)
For Ndx = LBound(arr) To ((UBound(arr) - LBound(arr) + 1) \ 2)
'swap the elements
Temp = arr(Ndx)
arr(Ndx) = arr(Ndx2)
arr(Ndx2) = Temp
' decrement the upper index
Ndx2 = Ndx2 - 1
Next Ndx
sliceCharByNum = arr()
Else
sliceCharByNum = arr()
End If
End Function
and the match by counting
Code:
'counts the number of matches of a string in an array that has one character per key
Function countMatchChar(ByRef arrayImport() As String, StringToMatch As Variant) As Long
Dim MatchString As String
Dim x As Long
Dim y As Long
MatchString = Nz(StringToMatch, "")
y = 0
For x = LBound(arrayImport) To UBound(arrayImport) 'define start and end of array
If InStr(1, arrayImport(x), MatchString, vbTextCompare) > 0 Then
y = y + 1
End If
Next x
countMatchChar = y
End Function
You could of course combine the two into one too but I figure I will post that later after this.