Need a macro. Separate values from a column and combined it in a different cell. Thanks

Farisha

New Member
Joined
Mar 24, 2011
Messages
47
Dear all,

I need your help. I have value in Column A, and Column B. In some cells the value in Column B comes with multiple value separated by comma. I need to separate the value in column B and put it in column G. The value should come in Column G in an order like, First Value from column V, second value from Column D, Third Value from E, 4th Value from Column F ( if there is any) and if it is blank, the 5 value should start from Column C second value and it should go on like this. I will appreciate any help . Thanks




Column AColumn BColumn CColumn DColumn EColumn FColumn GMatch Column A and G
AppleApple, Orange, BananaAppleOrangeBananaApple
OrangeMangoMangoOrange
BananaPeachPeachBanana
MangoAvocadoAvocadoMango
PeachPeach
AvocadoAvocado
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Can you have duplicate values in col B? If so do you want to display that once in col G or multiple times?
 
Upvote 0
Ok, how about
VBA Code:
Sub Farisha()
   Dim Lst As Object
   Dim Sp As Variant
   Dim i As Long
   Dim Cl As Range
   
   Set Lst = CreateObject("system.collections.arraylist")
   For Each Cl In Range("B2", Range("B" & Rows.Count).End(xlUp))
      Sp = Split(Cl, ",")
      For i = 0 To UBound(Sp)
         Lst.Add Trim(Sp(i))
      Next i
   Next Cl
   Range("G2").Resize(Lst.Count).Value = Application.Transpose(Lst.toarray)
End Sub
 
Upvote 0
Ok, how about
VBA Code:
Sub Farisha()
   Dim Lst As Object
   Dim Sp As Variant
   Dim i As Long
   Dim Cl As Range
  
   Set Lst = CreateObject("system.collections.arraylist")
   For Each Cl In Range("B2", Range("B" & Rows.Count).End(xlUp))
      Sp = Split(Cl, ",")
      For i = 0 To UBound(Sp)
         Lst.Add Trim(Sp(i))
      Next i
   Next Cl
   Range("G2").Resize(Lst.Count).Value = Application.Transpose(Lst.toarray)
End Sub
Pefect. It worked very well. Thanks for making my life soooo easy. :)
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,627
Messages
6,120,610
Members
448,973
Latest member
ChristineC

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