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??
Hope you see what I am getting at..VB Code:
Option Explicit Function mySplit(strToSplt, strSplitOn) 'Split Function Dim ip1, ip2 Dim strArray() Dim iCount ip1 = 1: ip2 = 1 Do ip2 = InStr(ip1, strToSplt, strSplitOn) If ip2 = 0 Then ip2 = Len(strToSplt) + 1 End If If iCount Mod 100 = 0 Then ReDim Preserve strArray(iCount + 100) End If strArray(iCount) = Mid$(strToSplt, ip1, ip2 - ip1) ip1 = ip2 + Len(strSplitOn) iCount = iCount + 1 Loop Until ip2 >= Len(strToSplt) ReDim Preserve strArray(iCount - 1) mySplit = strArray End Function Sub test() Dim rw Dim intRow As Long Dim Mystr, strParams, strUserName, strContext, strSubContext, strTree As String intRow = 1 For Each rw In Worksheets("allusers").Cells(1, 1).CurrentRegion.Rows 'Do this for every row in excel intRow = intRow 'get the row number (Im not really sure how this works but it does further down Mystr = rw.Cells(1, 1).Value 'Get the string to split up strParams = mySplit(Mystr, ".") 'Send string tho be split If isArray(strParams) Then 'assign the split string to the right variables strUserName = Trim(strParams(0)) strSubContext = Trim(strParams(1)) strContext = Trim(strParams(2)) strTree = Trim(strParams(3)) End If rw.Range("C" & intRow).Value = strUserName 'put the username in cell D and the row rw.Range("D" & intRow).Value = strSubContext 'put the context1 if it exsits in cell D and the row rw.Range("E" & intRow).Value = strContext 'put the context 2 in cell D and the row rw.Range("F" & intRow).Value = strTree 'put the tree in cell E and the row Next rw End Sub




Reply With Quote