
Splitting Strings in a Macro
#1
Posted 13 February 2012 - 04:00 AM
Register to Remove
#2
Posted 28 February 2012 - 12:21 AM
I'd love to help you, but am unsure what the end result would be in your example. Is it that you want the two strings to be as follows?
Plus: +11+12+14.5
Minus: -10-13-0.13
If this is the case, you can get results similar to this with the following:
Dim str As String, result As Object Dim strMinus As String, strPlus As String str = "-10+11+12-13+14.5-0.13" Dim r As New RegExp With r .Pattern = "([+-]?[0-9]+(\.[0-9]+)?)" .Global = True Set result = .Execute(str) End With For i = 0 To result.Count - 1 Dim val As String val = result(i).Value If (Left(val, 1) = "-") Then strMinus = strMinus & val Else strPlus = strPlus & val End If Next i
I tested and it works for the string you gave me, just turn the above into a function and pass the string in as a parameter. You'll also need to add a reference to the Microsoft VBScript Regular Expressions Library to your spreadsheet to get the regular expressions working.
Regards,
Ax
Kaspersky Online Virus Scan | Trend Micro HouseCall | Windows Live OneCare | Secunia Software Inspector
#3
Posted 02 March 2012 - 05:06 AM
Edited by K e n, 02 March 2012 - 05:07 AM.
#4
Posted 03 March 2012 - 01:20 AM
Kaspersky Online Virus Scan | Trend Micro HouseCall | Windows Live OneCare | Secunia Software Inspector
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users