VBA date clean up - vba

I have some date data that I want to clean up and remove any text that is in the date.
I have the following code that outputs data to a worksheet, and it has a separate datecleanup function that does some of the date cleanup if there is a missing date, or it is only 4 digits, however I am still getting data outputted that contains a mixture of dates and text (examples below).
Main function:
Function TetanusLoad(col As String, col2 As String)
Dim i As Long, j As Long, k As Long
j = Worksheets("CI").Range("A" & Rows.Count).End(xlUp).Row + 1
k = Worksheets("Error").Range("A" & Rows.Count).End(xlUp).Row + 1
For i = 2 To lstrow
If Len(Worksheets("Data").Range(col & i).Value) = 0 And
Len(Worksheets("Data").Range(col2 & i).Value) = 0 Then
GoTo EmptyRange
Else
strDate = spacedate(Worksheets("Data").Range(col & i).Value)
Worksheets("CI").Range("A" & j & ":C" & j).Value =
Worksheets("Data").Range("F" & i & ":H" & i).Value
Select Case Worksheets("Data").Range(col2 & i).Value
Case "Tdap"
Worksheets("CI").Range("D" & j).Value = "TDA"
Case "Td"
Worksheets("CI").Range("D" & j).Value = "TD"
Case Else
Worksheets("CI").Range("D" & j).Value = "REVIEW"
End Select
Worksheets("CI").Range("E" & j).Value = datecleanup(strDate)
j = j + 1
End If
EmptyRange:
Next i
End Function
datecleanup function:
Function datecleanup(inputdate As Variant) As Variant
If Len(inputdate) = 0 Then
inputdate = "01/01/1901"
Else
If Len(inputdate) = 4 Then
inputdate = "01/01/" & inputdate
Else
If InStr(1, inputdate, ".") Then
inputdate = Replace(inputdate, ".", "/")
End If
End If
End If
datecleanup = inputdate
End Function
Sample data output examples for column E that I am trying to correct:
07/06/1993 - HAD ALLERGIC REACTION ; ARM SWELLED AND GOT RED AND HOT
09/23/2004 - REPORTS REACTION TO TETANUS SHOT
12/03/2015 Rubelo reported
I don't want the additional text included, as this should be a date only field. How can I accomplish this? Ideally I would like it to be referenced in the datecleanup function as other functions use this as well.

Taking Nathan's and expanding on it in case of text before date:
Function dateclean(strInput As String) As String
Dim strSplits As Variant, i As Integer, dateFound As String
strSplits = Split(strInput, Chr(32))
For i = 0 To UBound(strSplits)
If strSplits(i) Like "*/*/*" Then
dateFound = strSplits(i)
Exit For
End If
Next i
dateclean = dateFound
End Function

Something like this
function dateclean(strInput as string) as string
dateclean=split(strInput,chr(32))(0)
end function

Not sure what all your code is meant to be doing - it doesn't say where lstRow is defined.
This sample has your examples in the range Data!D2:D4.
The output will appear in the range CI!D2:D4.
Note - I've updated some variable names (although they're not used).
E.g. It's a bit more obvious what CI_LastRow contains, rather than figuring out what j stands for.
Sub Test()
TetanusLoad 4, 5
End Sub
Public Sub TetanusLoad(col As Long, col2 As Long)
Dim CI_LastRow As Long, Error_LastRow As Long
Dim Data_Range As Range, rCell As Range
CI_LastRow = Worksheets("CI").Cells(Rows.Count, 1).End(xlUp).Row + 1
Error_LastRow = Worksheets("Error").Cells(Rows.Count, 1).End(xlUp).Row + 1
'This is the range containing your date/text strings.
With Worksheets("Data")
Set Data_Range = .Range(.Cells(1, col), .Cells(.Rows.Count, col).End(xlUp))
End With
For Each rCell In Data_Range
Worksheets("CI").Cells(rCell.Row, 5) = datecleanup(rCell)
Next rCell
End Sub
Function datecleanup(inputdate As Variant) As Variant
Dim re, match
Set re = CreateObject("vbscript.regexp")
re.Pattern = "[\d]+[\/-][\d]+[\/-][\d]+"
re.Global = True
For Each match In re.Execute(inputdate)
If IsDate(match.Value) Then
datecleanup = CDate(match.Value)
Exit For
End If
Next
Set re = Nothing
End Function
The datecleanup function is a copy of the FormatOutput function found on this link:
VBA Regular Expression to Match Date

Related

Date cleanup function

I have this VBA module in my Excel spreadsheet that attempts to clean up the date data, which contains various issues with text being combined with date information. Here is my main load function:
Public lstrow As Long, strDate As Variant, stredate As Variant
Sub importbuild()
lstrow = Worksheets("Data").Range("G" & Rows.Count).End(xlUp).Row
Function DateOnlyLoad(col As String, col2 As String, colcode As String)
Dim i As Long, j As Long, k As Long
j = Worksheets("CI").Range("A" & Rows.Count).End(xlUp).Row + 1
k = Worksheets("Error").Range("A" & Rows.Count).End(xlUp).Row + 1
For i = 2 To lstrow
strDate = spacedate(Worksheets("Data").Range(col & i).Value)
stredate = spacedate(Worksheets("Data").Range(col2 & i).Value)
If (Len(strDate) = 0 And (col2 = "NA" Or Len(stredate) = 0)) Or InStr(1,
UCase(Worksheets("Data").Range(col & i).Value), "EXP") > 0 Then
GoTo EmptyRange
Else
Worksheets("CI").Range("A" & j & ":C" & j).Value =
Worksheets("Data").Range("F" & i & ":H" & i).Value
Worksheets("CI").Range("D" & j).Value = colcode
Worksheets("CI").Range("E" & j).Value = datecleanup(strDate)
'Worksheets("CI").Range("L" & j).Value = dateclean(strDate)
Worksheets("CI").Range("F" & j).Value = strDate
If col2 <> "NA" Then
If IsEmpty(stredate) = False Then
Worksheets("CI").Range("F" & j).Value = datecleanup(stredate)
End If
End If
j = j + 1
End If
EmptyRange:
Next i
End Function
datecleanup function:
Function datecleanup(inputdate As Variant) As Variant
If Len(inputdate) = 0 Then
inputdate = "01/01/1901"
Else
If Len(inputdate) = 4 Then
inputdate = "01/01/" & inputdate
Else
If InStr(1, inputdate, ".") Then
inputdate = Replace(inputdate, ".", "/")
End If
End If
End If
datecleanup = Split(inputdate, Chr(32))(0)
Sample Output:
Column A Column B Column C Column D Column E Column F
125156 Wills, C 11/8/1960 MMR1 MUMPS MUMPS TITER 02/26/2008 POSITIVE
291264 Balti, L 09/10/1981 MMR1 (blank) Measles - 11/10/71 Rubella
943729 Barnes, B 10/10/1965 MMR1 MUMPS MUMPS TITER 10/08/2008 POSITIVE
The Split separates the date from the subsequent text and this works fine, however if there is text that occurs before the date then the output contains the first part of the text. I would like to get only the date (if it exists) from the string and display that, regardless of where it falls in the string. Below are sample results: Column E is the output from the Split logic, Column F is the entire string that is being evaluated from the other worksheet.
Desired Output from above examples: (Column E has correct dates extracted)
Column A Column B Column C Column D Column E Column F
125156 Wills, C 11/8/1960 MMR1 02/26/2008 MUMPS TITER 02/26/2008 POSITIVE
291264 Balti, L 09/10/1981 MMR1 11/10/71 Measles - 11/10/71 Rubella
943729 Barnes, B 10/10/1965 MMR1 10/08/2008 MUMPS TITER 10/08/2008 POSITIVE
What else can I add into my datecleanup function to further refine this? Thanks in advance!
Avoiding a regex, such as in the way suggested in comments is usually a good idea, but in for a penny, in for a pound:
① Use a regex mm/dd/yyyy
(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)[0-9]{2}
That pattern comes from ipr101's answer, and proposes a good regex for validating an actual date for mm/dd/yyyy. I have adjusted to correctly escape a couple of characters.
You would need to adjust if can be less digits or different format. Some examples given below.
You could use the function below as:
Worksheets("CI").Range("F" & j).Value = RemoveChars(datecleanup(stredate))
Example test:
Option Explicit
Public Sub test()
Debug.Print RemoveChars("Measles - 11/10/1971 Rubella")
End Sub
Public Function RemoveChars(ByVal inputString As String) As String
Dim regex As Object, tempString As String
Set regex = CreateObject("VBScript.RegExp")
With regex
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = "(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9]{2}"
End With
If regex.test(inputString) Then
RemoveChars = regex.Execute(inputString)(0)
Else
RemoveChars = inputString
End If
End Function
② For dd/mm/yyyy use:
(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.](19|20)[0-9]{2}
③ And more flexible in case of single day or month (day before month), use:
([1-9]|[12][0-9]|3[01])[- \/.](0?[1-9]|1[012])[- \/.][0-9]{2,4}
You get the idea.
Note:
You can always use something generic like (\d{1,2}\/){2}\d{2,4}, and then validate the function return string with ISDATE(return value).

How to remove empty lines from cells in Excel (VBA)

Here's what I'm trying to achieve through all the cells in the worksheet containing a string, with limited success so far:
| EXAMPLE |
cell1_empty_line
cell1_text1
cell1_empty_line
+---------------------+
cell2_text1
cell2_emptyline
cell2_text2
+---------------------+
cell3_emptyline
cell3_emptyline
cell3_text1
+---------------------+
| EXPECTED RESULT |
cell1_text1
+---------------------+
cell2_text1
cell2_text2
+---------------------+
cell3_text1
+---------------------+
Any suggestion for such a macro?
Many thanks.
Use this macro to remove any empty lines inside all cells:
Sub TrimEmptyLines()
Dim cel As Range, s As String, len1 As Long, len2 As Long
For Each cel In ActiveSheet.UsedRange
If Not IsError(cel.Value2) Then
If InStr(1, cel.text, vbLf) > 0 Then
s = Trim(cel.Value2)
Do ' remove duplicate vbLf
len1 = Len(s)
s = Replace$(s, vbLf & vbLf, vbLf)
len2 = Len(s)
Loop Until len2 = len1
' remove vblf at beginning or at end
If Left$(s, 1) = vbLf Then s = Right$(s, Len(s) - 1)
If Right$(s, 1) = vbLf Then s = Left$(s, Len(s) - 1)
cel.value = Trim$(s)
End If
End If
Next
End Sub
This is general enough to handle any column of cells with any # of line feeds in each cell. It assumes all your values are in column "A" starting at row 1 of the active sheet:
Public Function RemoveDoubleLfs(str As String) As String
If InStr(str, vbLf & vbLf) > 0 Then
str = RemoveDoubleLfs(Replace(str, vbLf & vbLf, vbLf))
End If
RemoveDoubleLfs = str
End Function
Sub RemoveEmptyLines()
Dim i As Integer, lastRow As Integer
lastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row '
Dim val As String
For i = 1 To lastRow:
val = Cells(i, "A").Value
If InStr(1, val, vbLf) > 0 Then
val = RemoveDoubleLfs(val)
If Left(val, 1) = vbLf Then val = Right(val, Len(val) - 1)
If Right(val, 1) = vbLf Then val = Left(val, Len(val) - 1)
Cells(i, "A").Value = val
End If
Next
ActiveSheet.Rows.EntireRow.AutoFit
End Sub
The recursive replace function gets rid of double line feeds in the text of the cell. Once that's done there will be at most one VbLf at the beginning and end of the string. The last two if statements look for and remove the latter.
The autofit at the end is optional and is there purely to prettify the result; it just compacts the cells to their minimum height.
If you are working with just one cell and its blank lines within then one of these should work:
Cells.Replace what:=Chr(13), Replacement:="", LookAt:=xlPart
Cells.Replace what:=Chr(10), Replacement:="", LookAt:=xlPart
Before implementing this solution please set the values of the two variables at the top.
FirstDataColumn = 1
FirstDataRow = 2
This setting leaves starts with the first column but leaves out the first row which might contain column captions.
Sub RemoveBlanks()
Dim FirstDataColumn As Long, FirstDataRow As Long
Dim LastColumn As Long, LastRow As Long
Dim Tmp As Variant, Arr As Variant
Dim Counter As Integer
Dim C As Long, R As Long
FirstDataColumn = 1
FirstDataRow = 2
Application.ScreenUpdating = False
With ActiveSheet
With .UsedRange
LastColumn = .Columns.Count
LastRow = .Rows.Count
End With
For C = FirstDataColumn To LastColumn
ReDim Arr(LastRow, 0)
Counter = 0
For R = FirstDataRow To LastRow
Tmp = Trim(.Cells(R, C).Value)
If Len(Tmp) Then
Arr(Counter, 0) = Tmp
Counter = Counter + 1
End If
Next R
.Cells(FirstDataRow, C).Resize(LastRow, 1).Value = Arr
Next C
End With
Application.ScreenUpdating = True
End Sub

How to remove quotes using vba?

I have:
nuid="!,#,a-z"
But I do not want the double quotes. I want nuid=!,#,a-z
Suggest me ways to remove the start and end quotes
Here is my code:
sub highlight(nuid as string)
dim sh3 as worksheet
Set sh3 = Thisworkbook.Worksheets("Sheet1")
sh3.Select
Cells.Find("User ID").Select
ActiveCell.Offset(1, 0).Select
nuid = Replace(nuid, """", "")
Set rn = sh3.UsedRange
k = rn.Rows.Count + rn.Row - 1
For x = 1 To k
If ActiveCell.Value Like nuid Then
Selection.Interior.Color = vbYellow
Else
Selection.Interior.ColorIndex = xlNone
End If
ActiveCell.Offset(1, 0).Select 'moves activecell down one row.
Next
end sub
From my gui, i will enter special characters which will be stored in the variable nuid.I want only the special characters and not the quotes around it
Also you can try:
nuid = Replace(nuid, Chr(34), vbNullString)
But you can have problem if quotes not the first nor the last character, for example: "!,#,"a-z".
In that case you can try:
nuid = Mid(nuid, 2, Len(nuid) - 1) This will cut the first and last character
Edit:
It seems to me that the quotes that you see indicates the type of a variable string.
Edit2 - watch window
Results:
Edit3 - with sub 4 Sagi:
Sub Highlight4Sagi(SpecChar As String)
Dim Column As Integer
SpecChar = "!##"
ThisWorkbook.Worksheets(1).Select
Column = Cells.Find("User ID").Column
LastRow = Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
For i = 2 To LastRow 'loop each row in column "User ID"
For j = 1 To Len(SpecChar) 'loop every specchar: ! and # and # and find him in each cells
If InStr(1, Cells(i, Column), Mid(SpecChar, j, 1)) > 0 Then
Cells(i, Column).Interior.ColorIndex = 6
Exit For
Else
Cells(i, Column).Interior.ColorIndex = 0
End If
Next j
Next i
End Sub
Proper Function:
Sub Test()
Debug.Print RemoveOuterQuotes(Cells(2, 1).Value)
End Sub
Public Function RemoveOuterQuotes(ByVal Str As String) As String
If Left(Str, 1) = """" Then
Str = Right(Str, Len(Str) - 1)
End If
If Right(Str, 1) = """" Then
Str = Left(Str, Len(Str) - 1)
End If
'Debug.Print Str
'Stop
RemoveOuterQuotes = Str
End Function
Basically escape a " with ""
Below should help
nuid = replace (nuid, """", "")
additional variant
Sub highlight(nuid As String)
Dim sh3 As Worksheet, Cl&, Lrow&, x&, oCell As Range
Set sh3 = ThisWorkbook.Worksheets("Sheet1")
Cl = sh3.Cells.Find("User ID").Column
Frow = sh3.Cells.Find("User ID").Row + 1
Lrow = Cells.Find("*", , , , xlByRows, xlPrevious).Row
For Each oCell In sh3.Range(Cells(Frow, Cl), Cells(Lrow, Cl))
If oCell.Value <> "" Then
For x = 1 To Len(nuid)
If oCell.Value Like "*" & Mid(nuid, x, 1) & "*" Then
oCell.Interior.Color = vbYellow
Exit For
Else
oCell.Interior.Color = xlNone
End If
Next x
End If
Next oCell
End Sub
output
but if you need to find, for instance the cells which contain any char in low case [a-z] then another aproach should be used

How do i add dashes till my cell value equals to five in vba

How do i add dashes(-) til my cell value = 5, If my length character is not equal to five and i have a 4 character, for ex A B... what i want it to do if i have cell value less then 5 then i want it to replace with dashes(-) till my cell length value reach to 5 character. Here is my Code and image... IMAGE will make more sense.. let me know if there is any confusion.
Sub xn()
Dim x As Integer, lastrow As Long, a As Long, i As Long
Dim xcell As String
a = 1
lastrow = Worksheets("Sheet2").UsedRange.Rows.Count + 1
For i = a To lastrow
xcell = Worksheets("Sheet2").Range("A" & i).Value
Do Until Len(xcell) = 5
If Len(xcell) <> 5 Then
Worksheets("Sheet2").Range("C" & i) = Replace(xcell, " ", "_")
Else
Exit Do
End If
Loop
Next i
End Sub
try this
Sub test()
Dim lastrow&, i&, xcell$, z%
lastrow = Sheet2.Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To lastrow
xcell = Replace(Sheet2.Range("A" & i).Value, " ", "")
If Len(xcell) < 5 And xcell <> "" Then
z = 5 - Len(xcell)
Sheet2.Cells(i, "C").Value = Left(xcell, Len(xcell) - 1) & _
WorksheetFunction.Rept("-", z) & Right(xcell, 1)
Else
Sheet2.Cells(i, "C").Value = xcell
End If
Next i
End Sub
output
This line isn't going to do anything unless there's already spaces padding the end of the string:
Worksheets("Sheet2").Range("C" & i) = Replace(xcell, " ", "_")
You need to check the length, if it's less than five, add 5 - length characters to the end of it:
Sub xn()
Dim lastrow As Long
Dim i As Long
Dim xcell As String
lastrow = Worksheets("Sheet2").UsedRange.Rows.Count + 1
For i = 1 To lastrow
xcell = Worksheets("Sheet2").Range("A" & i).Value
If Len(xcell) < 5 Then
Worksheets("Sheet2").Range("C" & i) = xcell & String$(Len(xcell) - 5, "_")
End If
Next i
End Sub
You can also leave out the variable 'a' - it's basically a constant in the code you posted.

Trying to extract data from curly braces but not working

I need to sync up the values in the curly braces {} found in column C and put them against the user id in column F as seen below.
E.g. on the Emails sheet
becomes this on a new sheet
Sub CopyConditional()
Dim wshS As Worksheet
Dim WhichName As String
Set wshS = ActiveWorkbook.Sheets("Emails")
WhichName = "NewSheet"
Const NameCol = "C"
Const FirstRow = 1
Dim LastRow As Long
Dim SrcRow As Long
Dim TrgRow As Long
Dim wshT As Worksheet
Dim cpt As String
Dim user As String
Dim computers() As String
Dim computer As String
On Error Resume Next
Set wshT = Worksheets(WhichName)
If wshT Is Nothing Then
Set wshT = Worksheets.Add(After:=wshS)
wshT.Name = WhichName
End If
On Error GoTo 0
If wshT.Cells(1, NameCol).value = "" Then
TrgRow = 1
Else
TrgRow = wshT.Cells(wshT.Rows.Count, NameCol).End(xlUp).Row + 1
End If
LastRow = wshS.Cells(wshS.Rows.Count, NameCol).End(xlUp).Row
For SrcRow = FirstRow To LastRow
cpt = wshS.Range("C" & SrcRow).value
user = wshS.Range("F" & SrcRow).value
If InStr(cpt, ":") Then
cpt = Mid(cpt, InStr(1, cpt, ":") + 1, Len(cpt))
End If
If InStr(cpt, ";") Then
computers = Split(cpt, ";")
For i = 0 To UBound(computers)
If computers(i) <> "" Then
wshT.Range("A" & TrgRow).value = user
wshT.Range("B" & TrgRow).value = Mid(Left(computers(i), Len(computers(i)) - 1), 2)
TrgRow = TrgRow + 1
End If
Next
Else
computer = cpt
If computer <> "" Then
wshT.Range("A" & TrgRow).value = user
wshT.Range("B" & TrgRow).value = Mid(Left(computer, Len(computer) - 1), 2)
TrgRow = TrgRow + 1
End If
End If
Next SrcRow
End Sub
I managed to resolve it with the above code but there are 3 niggling issues:
1) The first curly brace is always copied, how do I omit this so something like {Computer1 looks like Computer 1
2) Where there are two computers in a row, then the output looks something like this:
when it should really be split into two different rows i.e.
User 1 | Computer 1
User 1 | Computer 2
3) If there is text after the last curly brace with text in it e.g. {Computer1};{Computer2};Request submitted then that text is added as a new row, I don't want this, I want it to be omitted e.g.
should just be:
User 1 | Computer 1
User 1 | Computer 2
How do I go about rectifying these issues?
Try this:
Sub Collapse()
Dim uRng As Range, cel As Range
Dim comps As Variant, comp As Variant, r As Variant, v As Variant
Dim d As Dictionary '~~> Early bind, for Late bind use commented line
'Dim d As Object
Dim a As String
With Sheet1 '~~> Sheet that contains your data
Set uRng = .Range("F1", .Range("F" & .Rows.Count).End(xlUp))
End With
Set d = CreateObject("Scripting.Dictionary")
With d
For Each cel In uRng
a = Replace(cel.Offset(0, -3), "{", "}")
comps = Split(a, "}")
Debug.Print UBound(comps)
For Each comp In comps
If InStr(comp, "Computer") <> 0 _
And Len(Trim(comp)) <= 10 Then '~~> I assumed max Comp# is 99
If Not .Exists(cel) Then
.Add cel, comp
Else
If IsArray(.Item(cel)) Then
r = .Item(cel)
ReDim Preserve r(UBound(r) + 1)
r(UBound(r)) = comp
.Item(cel) = r
Else
r = Array(.Item(cel), comp)
.Item(cel) = r
End If
End If
End If
Next
Next
End With
For Each v In d.Keys
With Sheet2 '~~> sheet you want to write your data to
If IsArray(d.Item(v)) Then
.Range("A" & .Rows.Count).End(xlUp).Offset(1, 0) _
.Resize(UBound(d.Item(v)) + 1) = v
.Range("B" & .Rows.Count).End(xlUp).Offset(1, 0) _
.Resize(UBound(d.Item(v)) + 1) = Application.Transpose(d.Item(v))
Else
.Range("A" & .Rows.Count).End(xlUp).Offset(1, 0) = v
.Range("B" & .Rows.Count).End(xlUp).Offset(1, 0) = d.Item(v)
End If
End With
Next
Set d = Nothing
End Sub
Above code uses Replace and Split Function to pass your string to array.
a = Replace(cel.Offset(0, -3), "{", "}") '~~> standardize delimiter
comps = Split(a, "}") '~~> split using standard delimiter
Then information are passed to dictionary object using User as key and computers as items.
We filter the items passed to dictionary using Instr and Len Function
If InStr(comp, "Computer") <> 0 _
And Len(Trim(comp)) <= 10 Then
As I've commented, I assumed your max computer number is 99.
Else change 10 to whatever length you need to check.
Finally we return the dictionary information to the target worksheet.
Note: You need to add reference to Microsoft Scripting Runtime if you prefer early bind
Result: I tried it on a small sample data patterned on how I see it in you SS.
So assuming you have this data in Sheet1:
Will output data in Sheet2 like this:
I use a custom parse function for this type of operation:
Sub CopyConditional()
' some detail left out
Dim iRow&, Usern$, Computer$, Computers$
For iRow = ' firstrow To lastrow
Usern = Sheets("Emails").Cells(iRow, "F")
Computers = Sheets("Emails").Cells(iRow, "C")
Do
Computer = zParse(Computers) ' gets one computer
If Computer = "" Then Exit Do
' Store Computer and Usern
Loop
Next iRow
End Sub
Function zParse$(Haystack$) ' find all {..}
Static iPosL& '
Dim iPosR&
If iPosL = 0 Then iPosL = 1
iPosL = InStr(iPosL, Haystack, "{") ' Left
If iPosL = 0 Then Exit Function ' no more
iPosR = InStr(iPosL, Haystack, "}") ' Right
If iPosR = 0 Then MsgBox "No matching }": Stop
zParse = Mid$(Haystack, iPosL + 1, iPosR - iPosL - 1)
iPosL = iPosR
End Function
1) Use the Mid function to drop the first character:
str = "{Computer1"
str = Mid(str,2)
now str = "Computer1"
2) You can use the Split function to separate these out and combine with the Mid function above
str = "{Computer1}{Computer2}"
splt = Split(str,"}")
for a = 0 to Ubound(splt)
result = Mid(splt(a),2)
next a
3) Add a conditional statement to the above loop
str = "{Computer1}{Computer2}"
splt = Split(str,"}")
for a = 0 to Ubound(splt)
if Left(splt(a),1) = "{" then result = Mid(splt(a),2)
next a
Use this loop and send each result to the desired cell (in the for-next loop) and you should be good to go.