Hi Team,
I have a string value needs to split a string value, with comma Separated.
if Count of splitted value greater than 3 then
Add only 4 items to dictionary, First 3 value splitted and 4 the value all combined with space.
'Situation 1
str = "ABC 400 jan comment1 comment2"
'Situation 2
str2 = "ABC 500 Feb Comment1 Comment2 Comment3 Comment4"
Attempted code for situation1 , like that in situation 2 looking code.
Debug.Print dict(k)
Thanks
mg
I have a string value needs to split a string value, with comma Separated.
if Count of splitted value greater than 3 then
Add only 4 items to dictionary, First 3 value splitted and 4 the value all combined with space.
'Situation 1
str = "ABC 400 jan comment1 comment2"
'Situation 2
str2 = "ABC 500 Feb Comment1 Comment2 Comment3 Comment4"
Attempted code for situation1 , like that in situation 2 looking code.
Debug.Print dict(k)
VBA Code:
Sub test()
Dim str As String
Dim arr As Variant
Dim k As String
k = "Key"
Dim cnt As Long
'Situation 1
str = "ABC 400 jan comment1 comment2"
'Situation 2
str = "ABC 500 Feb Comment1 Comment2 Comment3 Comment4"
'Below code for situation 1
Dim dict As New Scripting.Dictionary
arr = Split(str, " ")
cnt = UBound(arr)
If cnt > 3 Then
arr(3) = arr(4) & " " & arr(5)
dict.Add k, Array(arr(0), arr(1), arr(2), arr(3))
Debug.Print dict(k)
End If
End Sub
Thanks
mg