single cell split in two cell and loop until find cell empty help in vba

manojxls

New Member
Joined
Dec 21, 2017
Messages
32
Office Version
  1. 365
  2. 2007
  3. 2003 or older
Platform
  1. Windows
Hi Team, i need help on below sample excel vba
i have data in A column with two word in same cell i need to split in to two cell also amount need to divide half these should done until a column find blank cell.
ithe result should show as shown as right.

costcentre1 & costcentre2400costcentre1 =400/2
costcent4 & costcentr25500costcentre2=400/2
costcent4 =500/2
costcentr25=500/2
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
With Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Column1", Splitter.SplitTextByDelimiter(" & ", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1"),
    #"Inserted Division" = Table.AddColumn(#"Split Column by Delimiter", "Division", each [Column2] / 2, type number),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Division",{"Column2"})
in
    #"Removed Columns"

Book3
ABCDE
1Column1Column2Column1Division
2costcentre1 & costcentre2400costcentre1200
3costcent4 & costcentr25500costcentre2200
4costcent4250
5costcentr25250
Sheet1
 
Upvote 0
With Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Column1", Splitter.SplitTextByDelimiter(" & ", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1"),
    #"Inserted Division" = Table.AddColumn(#"Split Column by Delimiter", "Division", each [Column2] / 2, type number),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Division",{"Column2"})
in
    #"Removed Columns"

Book3
ABCDE
1Column1Column2Column1Division
2costcentre1 & costcentre2400costcentre1200
3costcent4 & costcentr25500costcentre2200
4costcent4250
5costcentr25250
Sheet1

Hi Alan, thanks for sharing i dont find where is power query. but the result you share yes i want that. can you help me in vba or step where i paste code in power query.
 
Upvote 0
Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

- Follow this link to learn how to install Power Query in Excel 2010 / 2013.

- Follow this link for an introduction to Power Query functionality.

- Follow this link for a video which demonstrates how to use Power Query code provided.
 
Upvote 0
yes i found power query can you help me
below code i need for "&" ,"," -both character as some cell have & and some cell have 'couma

{"Column1", Splitter.SplitTextByDelimiter(" &,"," ", QuoteStyle.Csv)
 
Upvote 0
Replace with
Power Query:
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Column1", Splitter.SplitTextByAnyDelimiter({" & ",","} QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1"),
 
Upvote 0
Replace with
Power Query:
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Column1", Splitter.SplitTextByAnyDelimiter({" & ",","} QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1"),
getting error as
Token `'` expected.
 

Attachments

  • error.png
    error.png
    19.6 KB · Views: 3
Upvote 0
With 365 formula, try:
Book1
ABCDE
1costcentre1 & costcentre2400costcentre1 200
2costcent4 & costcentr25500 costcentre2200
3costcent4 250
4 costcentr25250
Sheet2
Cell Formulas
RangeFormula
D1:E4D1=HSTACK(TEXTSPLIT(TEXTJOIN("&",TRUE,A1:A2),,"&"),INDEX(B1:B2,ROUNDUP(SEQUENCE(ROWS(A1:A2)*2)/2,0))/2)
Dynamic array formulas.
 
Upvote 1
With the following example, this Mcode works for me.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Column1", Splitter.SplitTextByAnyDelimiter({" & ",", "}, QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1"),
    #"Inserted Division" = Table.AddColumn(#"Split Column by Delimiter", "Division", each [Column2] / 2, type number),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Division",{"Column2"})
in
    #"Removed Columns"

Book4
ABCDE
1Column1Column2Column1Division
2costcentre1 & costcentre2400costcentre1200
3costcent4 & costcentr25500costcentre2200
4costcent5, costcent6600costcent4250
5costcentr25250
6costcent5300
7costcent6300
Sheet1


My apologies, in my previous post, I was missing a comma. The above code is tested and works.
 
Upvote 0
Solution
thanks alansidman its works 95% i think i first need to clean data as many space,comma and & is there. thanks Cubist . many thanks all.
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,109
Members
452,302
Latest member
TaMere

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