I have the following code, and what it is doing is going through a spreadsheet in excel and splitting up the string that is dumped out of Novell. What it does is for example it splits "username.context.tree" into three parts. This works fine except when it comes to things like "username.subcontext.context.tree" or "username.tree". So how would i go about making choices and giving me the right bits in the places??

VB Code:
  1. Option Explicit
  2. Function mySplit(strToSplt, strSplitOn) 'Split Function
  3.     Dim ip1, ip2
  4.     Dim strArray()
  5.     Dim iCount
  6.    
  7.    
  8.     ip1 = 1: ip2 = 1
  9.     Do
  10.       ip2 = InStr(ip1, strToSplt, strSplitOn)
  11.       If ip2 = 0 Then
  12.         ip2 = Len(strToSplt) + 1
  13.       End If
  14.      
  15.       If iCount Mod 100 = 0 Then
  16.         ReDim Preserve strArray(iCount + 100)
  17.       End If
  18.       strArray(iCount) = Mid$(strToSplt, ip1, ip2 - ip1)
  19.      
  20.       ip1 = ip2 + Len(strSplitOn)
  21.       iCount = iCount + 1
  22.      
  23.     Loop Until ip2 >= Len(strToSplt)
  24.    
  25.     ReDim Preserve strArray(iCount - 1)
  26.     mySplit = strArray
  27.    
  28. End Function
  29.  
  30. Sub test()
  31. Dim rw
  32. Dim intRow As Long
  33. Dim Mystr, strParams, strUserName, strContext, strSubContext, strTree As String
  34.  
  35. intRow = 1
  36. For Each rw In Worksheets("allusers").Cells(1, 1).CurrentRegion.Rows 'Do this for every row in excel
  37.     intRow = intRow 'get the row number (Im not really sure how this works but it does further down
  38.     Mystr = rw.Cells(1, 1).Value 'Get the string to split up
  39.     strParams = mySplit(Mystr, ".") 'Send string tho be split
  40.     If isArray(strParams) Then 'assign the split string to the right variables
  41.         strUserName = Trim(strParams(0))
  42.         strSubContext = Trim(strParams(1))
  43.         strContext = Trim(strParams(2))
  44.         strTree = Trim(strParams(3))
  45.     End If
  46.     rw.Range("C" & intRow).Value = strUserName 'put the username in cell D and the row
  47.     rw.Range("D" & intRow).Value = strSubContext 'put the context1 if it exsits in cell D and the row
  48.     rw.Range("E" & intRow).Value = strContext 'put the context 2 in cell D and the row
  49.     rw.Range("F" & intRow).Value = strTree 'put the tree in cell E and the row
  50.  
  51. Next rw
  52.  
  53. End Sub
Hope you see what I am getting at..