I wrote this function in the past to help parse 100k+ rows worth of strings into cells. I gave up on it shortly after as it would take far too much time to do and opted to retrieve data in the form of workbooks and write their contents to arrays.
I'm more curious than anything, but solutions that work on both Mac and Windows would be appreciated.
I'm more curious than anything, but solutions that work on both Mac and Windows would be appreciated.
VBA Code:
Public Function Change_Delimiter_Not_Between_Quotes(ByRef Current_String As Variant, ByVal Delimiter As String, Optional ByVal Changed_Delimiter As String = ">Ý") As Variant
'returns a 0 based array
Dim String_Array() As String, X As Long, Right_CHR As String
If InStr(1, Current_String, Chr(34)) = 0 Then 'if there are no quotation marks then split with the supplied delimiter
Change_Delimiter_Not_Between_Quotes = Split(Current_String, Delimiter)
Exit Function
End If
Right_CHR = Right(Changed_Delimiter, 1) 'RightMost character in at least 2 character string that will be used as a replacement delimiter
'Replace ALL quotation marks with the ChangedDelimiter[Quotation mark] EX: " --> $+
Current_String = Replace(Current_String, Chr(34), Changed_Delimiter)
String_Array = Split(Current_String, Left(Changed_Delimiter, 1))
'1st character of Changed_Delimiter will be used to delimit a new array
'element [0] will be an empty string if the first value in the delmited string begins with a Quotation mark.
For X = LBound(String_Array) To UBound(String_Array) 'loop all elements of the array
If Left(String_Array(X), 1) = Right_CHR And Not Left(String_Array(X), 2) = Right_CHR & Delimiter Then
'If the string contains a valid comma
'Checked by if [the First character is the 2nd Character in the Changed Delimiter] and the 2nd character isn't the delimiter
'Then offset the string by 1 character to remove the 2nd portion of the changed Delimiter
String_Array(X) = Right(String_Array(X), Len(String_Array(X)) - 1)
Else
If Left(String_Array(X), 1) = Right_CHR Then 'If 1st character = 2nd portion of the Changed Delimiter
'Then offset string by 1 and then repalce all [Delimiter]
String_Array(X) = Replace(Right(String_Array(X), Len(String_Array(X)) - 1), Delimiter, Changed_Delimiter)
Else 'Just replace
String_Array(X) = Replace(String_Array(X), Delimiter, Changed_Delimiter)
End If
End If
Next X
'Join the Array elements back together {Do not add another delimiter] and split with the changed Delimiter
Change_Delimiter_Not_Between_Quotes = Split(Join(String_Array), Changed_Delimiter)
Erase String_Array
End Function