Need Additions to Excel 2010 Macro Changing List with Commas to New Rows

Alex20850

Board Regular
Joined
Mar 9, 2010
Messages
146
Office Version
  1. 365
Platform
  1. Windows
I have a macro created for me that takes list with values with commas (see first list) and turns it into a list with new rows for the values the comma values while adding the values from the original row (see second list).

TI have two problems with the macro:
1) It overwrites the original list. I would prefer that it create an new tab named Output or that it ask me for a name.
2) It has to be a particular column. I would like to be able to tell it which column to use.

Sub Commas_to_Rows()
Dim rng As Range
Dim rngLotNos As Range
Dim arrLotNos
Set rng = Range("A2")

While rng.Value <> ""
arrLotNos = Split(rng.Offset(, 4).Value, ",")
If UBound(arrLotNos) > 0 Then
rng.Offset(1).Resize(UBound(arrLotNos)).EntireRow.Insert
rng.Resize(, 7).Copy rng.Resize(UBound(arrLotNos) + 1)
rng.Offset(, 4).Resize(UBound(arrLotNos) + 1) = Application.Transpose(arrLotNos)
End If
Set rng = rng.Offset(UBound(arrLotNos) + 1)
Wend

End Sub


OrderPresidentField 2Field 3OccupationsState
1George WashingtonLand Surveyor,Farmer,Military Officer Virginia
2John AdamsLawyer,Farmer Massachusetts
3Thomas JeffersonLand Surveyor,Writer,Inventor,Lawyer,Architect,Farmer,Diplomat,Linguist Virginia
4James MadisonFarmer Virginia
5James MonroeFarmer,Lawyer Virginia
6John Quincy AdamsLawyer Massachusetts
7Andrew JacksonMilitary Officer,Lawyer Tennessee

<tbody>
</tbody>

and turns it into a list like this:

OrderPresidentField 2Field 3OccupationsState
1George WashingtonLand Surveyor Virginia
1George WashingtonFarmer Virginia
1George WashingtonMilitary Officer Virginia
2John AdamsLawyer Massachusetts
2John AdamsFarmer Massachusetts
3Thomas JeffersonLand Surveyor Virginia
3Thomas JeffersonWriter Virginia
3Thomas JeffersonInventor Virginia
3Thomas JeffersonLawyer Virginia
3Thomas JeffersonArchitect Virginia
3Thomas JeffersonFarmer Virginia
3Thomas JeffersonDiplomat Virginia
3Thomas JeffersonLinguist Virginia
4James MadisonFarmer Virginia
5James MonroeFarmer Virginia
5James MonroeLawyer Virginia
6John Quincy AdamsLawyer Massachusetts
7Andrew JacksonMilitary Officer Tennessee
7Andrew JacksonLawyer Tennessee

<tbody>
</tbody>
 
Alex20850,

I just want the macro to stop and ask for the column letter that goes into this line where it currently has E:

What you are asking can get quite complicated.

Please answer all of the following questions.

1. Will the last used column in your raw data set ever go beyond column Z?

2. Will the column that contains the , characters to split, ever be column A?

3. Will the column that contains the , characters to split, ever be the last used column in your raw data set?
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Alex20850,



What you are asking can get quite complicated.

Please answer all of the following questions.

1. Will the last used column in your raw data set ever go beyond column Z? No

2. Will the column that contains the , characters to split, ever be column A? No

3. Will the column that contains the , characters to split, ever be the last used column in your raw data set?
The instructions could be that it isn't.
 
Upvote 0
Alex20850,

The instructions could be that it isn't.

Click on the Reply to Thread button, and just put the word BUMP in the thread. Then, click on the Post Quick Reply button, and someone else will assist you.
 
Upvote 0

Forum statistics

Threads
1,215,632
Messages
6,125,913
Members
449,274
Latest member
mrcsbenson

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