To be fair, I don't know if you can break it out that way, but I'll try:
Code:
spl = Split(Trim(strHex), " ")
This breaks the string into an array (like a group of cells but 'internal'), by braking up the string based on the " " (space) character.
Code:
grpCount = Int(UBound(spl) / 4) + 1
Counts the elements in the array, bearing in mind the first one is referred to as spl(0), so you have to round up. If your groups get bigger, you'll need to change this bit.
Code:
For i = 0 To grpCount - 1
This loops through the number of loops
goes through each group backwards, using this math
, so again you'd need to change the 3 and the 4 to suit your group length
Code:
separateReverseRegroup = separateReverseRegroup & spl(i * 4 + j)
Adds the individual chunks back into a string, one group at a time, starting with the last in the group and ending with the first in that group, including a space after each one
Code:
separateReverseRegroup = Trim(separateReverseRegroup)
removes the last space, as it isn't needed. It's easier to add it then remove it this way than to write an extra if statement to decide whether to add it or not.
Code:
Option Base 0
Function separateReverseRegroup(ByVal strHex As String) As String
Dim spl As Variant, grpCount As Integer, grpLen As Integer
grpLen = 4
spl = Split(Trim(strHex), " ")
grpCount = Int(UBound(spl) / grpLen) + 1
If (UBound(spl) + 1) Mod grpLen <> 0 Then
separateReverseRegroup = "Not in groups of " & grpLen
Else
For i = 0 To grpCount - 1
For j = grpLen - 1 To 0 Step -1
separateReverseRegroup = separateReverseRegroup & spl(i * grpLen + j) & " "
Next j
Next i
separateReverseRegroup = Trim(separateReverseRegroup)
End If
End Function
Added the variable grpLen to illustrate the previous points on group length
HTH