VBA Split function

Jurgus

New Member
Joined
Jul 23, 2022
Messages
11
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I need your help once more

I have data in csv:

word1,"word2 "word2" "word2" word2","word3","word4","word5","word6"

that I import to different excel sheet so I'm getting

"word1,""word2 ""word2"" ""word2"" word2"",""word3"",""word4"",""word5"",""word6"""

after using split

Split(value, ",")

I'm getting

"word1""word2 ""word2"" ""word2"" word2""""word3""""word4""""word5""""word6"""

My final goal is:

word1word2 "word2" "word2" word2word3word4word5word6

any ideas? :)

Thanks,
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Your explanation is confusing, so I am not clear about what you are trying to do.

Book2
ABCDEF
1"word1,"word2 "word2" "word2" word2","word3","word4","word5","word6"
2word1word2 "word2" "word2" word2word3word4word5word6
Sheet4


VBA Code:
Sub Test()
    Dim S As String, I As Long
    Dim SA As Variant, SB As Variant

    SA = Split(Replace(Range("A1").Value, Chr(34), ""), ",")
    SB = Split(SA(1), " ")
    
    For I = 0 To UBound(SB)
        Select Case I
        Case UBound(SB)
            S = S & SB(I) & " "
        Case Is > 0
            S = S & Chr(34) & SB(I) & Chr(34) & " "
        Case Else
            S = S & SB(I) & " "
        End Select
    Next I

    SA(1) = Trim(S)
    
    With Range("A2")
        .Resize(1, UBound(SA) + 1).Value = SA
    End With
End Sub
 
Upvote 0
Solution
Your explanation is confusing, so I am not clear about what you are trying to do.

Book2
ABCDEF
1"word1,"word2 "word2" "word2" word2","word3","word4","word5","word6"
2word1word2 "word2" "word2" word2word3word4word5word6
Sheet4


VBA Code:
Sub Test()
    Dim S As String, I As Long
    Dim SA As Variant, SB As Variant

    SA = Split(Replace(Range("A1").Value, Chr(34), ""), ",")
    SB = Split(SA(1), " ")
   
    For I = 0 To UBound(SB)
        Select Case I
        Case UBound(SB)
            S = S & SB(I) & " "
        Case Is > 0
            S = S & Chr(34) & SB(I) & Chr(34) & " "
        Case Else
            S = S & SB(I) & " "
        End Select
    Next I

    SA(1) = Trim(S)
   
    With Range("A2")
        .Resize(1, UBound(SA) + 1).Value = SA
    End With
End Sub
sorry for bad explanation, when I'm reading it now it can be really confusing :P but it works perfect, thank you
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top