J
James
Please help debug this. I'm trying to turn a text string deliminated with | into an array.
Option Compare Text
Function Txt_Ary(Txt As String) As Range 'Turns the string value to a multi value range
Dim Cnt As Integer
Dim n As Integer
Dim Tmp_Ary As Range
Dim Tmp_Txt As String
Dim Sel_Case As Integer
Txt_Ary = Tmp_Ary
With Application.WorksheetFunction
'Finds the number of values deliminated by a ;
Cnt = Len(Txt) - Len(.Substitute(Txt, "|", "")) + 1
'there is "" or only one value then select case 1 otherwise select case 2
If .IsError(.Find(Txt, "|")) Then
Sel_Case = 1
Else
Sel_Case = 2
End If
End With
Select Case Sel_Case
'Select if there are no | in the text string
Case 1
Txt_Ary = Txt
Exit Function
'Select if there is a | in the text string
Case 2
With Application.WorksheetFunction
Tmp_Txt = Txt
For n = 0 To Cnt
If .IsError(.Find(Tmp_Txt, "|")) Then
Tmp_Ary(n + 1) = Tmp_Txt
Else
Tmp_Ary(n + 1) = Left(Tmp_Txt, .Find("|", Tmp_Txt) - 1)
Tmp_Txt = .Substitute(Tmp_Txt, Left(Tmp_Txt, .Find("|", Tmp_Txt)), "")
End If
Next
End With
End Select
End Function
EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Option Compare Text
Function Txt_Ary(Txt As String) As Range 'Turns the string value to a multi value range
Dim Cnt As Integer
Dim n As Integer
Dim Tmp_Ary As Range
Dim Tmp_Txt As String
Dim Sel_Case As Integer
Txt_Ary = Tmp_Ary
With Application.WorksheetFunction
'Finds the number of values deliminated by a ;
Cnt = Len(Txt) - Len(.Substitute(Txt, "|", "")) + 1
'there is "" or only one value then select case 1 otherwise select case 2
If .IsError(.Find(Txt, "|")) Then
Sel_Case = 1
Else
Sel_Case = 2
End If
End With
Select Case Sel_Case
'Select if there are no | in the text string
Case 1
Txt_Ary = Txt
Exit Function
'Select if there is a | in the text string
Case 2
With Application.WorksheetFunction
Tmp_Txt = Txt
For n = 0 To Cnt
If .IsError(.Find(Tmp_Txt, "|")) Then
Tmp_Ary(n + 1) = Tmp_Txt
Else
Tmp_Ary(n + 1) = Left(Tmp_Txt, .Find("|", Tmp_Txt) - 1)
Tmp_Txt = .Substitute(Tmp_Txt, Left(Tmp_Txt, .Find("|", Tmp_Txt)), "")
End If
Next
End With
End Select
End Function
EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com