Data manipulation

Billy12excel

New Member
Joined
Nov 17, 2010
Messages
42
Received data file per first sheet1, looking to manipulate
results to = second sheet 1

Excel Workbook
ABCD
1LEVEL of AttainmentNational Office RegionName Upper and LowerRanking Position & Dollar Amount #1
2Quadruple:
3Top LevelNorth District, ILAlbert Einstein#2 - Percent of Increase 6.0%
4Top LevelNorth District, ILAlbert Einstein#2 - Dollar Increase $2,745
5Top LevelNorth District, ILAlbert Einstein#2 New Members 10
6Top LevelNorth District, ILAlbert Einstein#1 Member Renewals 16
7etc,etc,
8
9Triple:
10Mid LevelSouth Valley District, ILTony Tgier#1 NM 105.56%
11Mid LevelSouth Valley District, ILTony Tgier#1 - Percent of Increase 15.6%
12Mid LevelSouth Valley District, ILTony Tgier#1 - Dollar Increase $9,737
13etc,etc,
14
15Double:
16Lower LevelCentral District, ILCarter Mann#2 New Members 6
17Lower LevelCentral District, ILCarter Mann#6 - APD $1,150
18etc,etc,
19
20Single:
21Bottom LevelCentral Distric, ILAlexander Jones#9 - APD $209
Sheet1
Excel Workbook
ABCDEFG
1LEVEL of AttainmentNational Office RegionName Upper and LowerRanking Position & Dollar Amount #1Ranking Position & Dollar Amount #2Ranking Position & Dollar Amount #3Ranking Position & Dollar Amount #4
2Quadruple:
3Top LevelNorth District, ILAlbert Einstein#2 - Percent of Increase 6.0%#2 - Dollar Increase $2,745#2 New Members 10#1 Member Renewals 16
4etc,etc,
5
6Triple:
7Mid LevelSouth Valley District, ILTony Tgier#1 NM 105.56%#1 - Percent of Increase 15.6%#1 - Dollar Increase $9,737
8etc,etc,
9
10Double:
11Lower LevelCentral District, ILCarter Mann#2 New Members 6#6 - APD $1,150
12etc,etc,
13
14Single
15Bottom LevelCentral Distric, ILAlexander Jones#9 - APD $209
16etc,etc,
17
18Ideally all levels saved to separate csv files
Excel 2000 Sheet1
Excel 2000


Ideally all levels saved to separate csv files

Thank you for any help!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Unclear... How many .csv files do you expect, based on the sample source data (the first Sheet1)? What do you mean by "etc,etc," in the second Sheet1? Can you post the expected data for one of the .csv files?
 
Upvote 0
Hope this helps, this would be the final CSV result of the Quadruple Group, Triple would be similar, with one less Ranking Position & Dollar Amount#3 being the end. Double would one less ranking, Single = 1 ranking only. All Levels have several names with Double (20+) and single levels (50+) names and related data. Hence my hope for a way to massage this data. Thank You!
Excel Workbook
BCDEFG
1National Office RegionName Upper and LowerRanking Position & Dollar Amount #1Ranking Position & Dollar Amount #2Ranking Position & Dollar Amount #3Ranking Position & Dollar Amount #4
2
3North District, ILAlbert Einstein#2 - Percent of Increase 6.0%#2 - Dollar Increase $2,745#2 New Members 10#1 Member Renewals 16
4Central DistrictRom Issac#3 - Percent of Increase 5.4%#3 - Dollar Increase $1,846#2 New Members 10#2 Member Renewals 15
5West, ILJan Jones#4 - Percent of Increase 5.1%#5 - Dollar Increase $2,247#3 New Members 8#3 Member Renewals 11
Sheet1
Excel 2000
 
Upvote 0
On a copy of your workbook, and with the sheet containing the data being the active sheet, try the following macro...

<font face=Calibri><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br><br><SPAN style="color:#00007F">Sub</SPAN> CreateCSVFiles()<br><br>    <SPAN style="color:#00007F">Dim</SPAN> Categories <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> Category <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> strPath <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> SourceRng <SPAN style="color:#00007F">As</SPAN> Range<br>    <SPAN style="color:#00007F">Dim</SPAN> FoundCell <SPAN style="color:#00007F">As</SPAN> Range<br>    <SPAN style="color:#00007F">Dim</SPAN> Cell <SPAN style="color:#00007F">As</SPAN> Range<br>    <SPAN style="color:#00007F">Dim</SPAN> LastRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> LastColumn <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br><br>    LastRow = Cells(Rows.Count, "A").End(xlUp).Row<br>    <br>    <SPAN style="color:#00007F">For</SPAN> i = LastRow <SPAN style="color:#00007F">To</SPAN> 3 <SPAN style="color:#00007F">Step</SPAN> -1<br>        <SPAN style="color:#00007F">If</SPAN> Cells(i, "B").Value <> "" <SPAN style="color:#00007F">Then</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Cells(i, "B").Value = Cells(i - 1, "B").Value <SPAN style="color:#00007F">Then</SPAN><br>                <SPAN style="color:#00007F">Set</SPAN> SourceRng = Range(Cells(i, "D"), Cells(i, Columns.Count).End(xlToLeft))<br>                Cells(i - 1, "E").Resize(, SourceRng.Columns.Count).Value = SourceRng.Value<br>                Rows(i).Delete<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN> i<br>    <br>    <SPAN style="color:#007F00">'Change the path to the folder in which you want to save the .csv files</SPAN><br>    strPath = "C:\Users\Domenic\Desktop\Test\"<br>    <br>    <SPAN style="color:#00007F">If</SPAN> Right(strPath, 1) <> "\" <SPAN style="color:#00007F">Then</SPAN> strPath = strPath & "\"<br><br>    Categories = Array("Quadruple", "Triple", "Double", "Single")<br>    <br>    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> Category <SPAN style="color:#00007F">In</SPAN> Categories<br>        <SPAN style="color:#00007F">With</SPAN> Columns("A")<br>            <SPAN style="color:#00007F">Set</SPAN> FoundCell = .Find(Category, LookIn:=xlValues, lookat:=xlPart, MatchCase:=False)<br>            <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> FoundCell <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>                <SPAN style="color:#00007F">Open</SPAN> strPath & Category & ".csv" <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Output</SPAN> <SPAN style="color:#00007F">As</SPAN> #1<br>                    <SPAN style="color:#00007F">Write</SPAN> #1, "National Office Region";<br>                    <SPAN style="color:#00007F">Write</SPAN> #1, "Name Upper and Lower";<br>                    <SPAN style="color:#00007F">Write</SPAN> #1, "Ranking Position & Dollar Amount #1";<br>                    <SPAN style="color:#00007F">Write</SPAN> #1, "Ranking Position & Dollar Amount #2";<br>                    <SPAN style="color:#00007F">Write</SPAN> #1, "Ranking Position & Dollar Amount #3";<br>                    <SPAN style="color:#00007F">Write</SPAN> #1, "Ranking Position & Dollar Amount #4"<br>                    <SPAN style="color:#00007F">Set</SPAN> Cell = FoundCell.Offset(1, 0)<br>                    <SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">While</SPAN> Cell <> ""<br>                        LastColumn = Cells(Cell.Row, Columns.Count).End(xlToLeft).Column<br>                        <SPAN style="color:#00007F">For</SPAN> i = 2 <SPAN style="color:#00007F">To</SPAN> LastColumn<br>                            <SPAN style="color:#00007F">If</SPAN> i <> LastColumn <SPAN style="color:#00007F">Then</SPAN><br>                                <SPAN style="color:#00007F">Write</SPAN> #1, Cells(Cell.Row, i).Value;<br>                            <SPAN style="color:#00007F">Else</SPAN><br>                                <SPAN style="color:#00007F">Write</SPAN> #1, Cells(Cell.Row, i).Value<br>                            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>                        <SPAN style="color:#00007F">Next</SPAN> i<br>                        <SPAN style="color:#00007F">Set</SPAN> Cell = Cell.Offset(1, 0)<br>                    <SPAN style="color:#00007F">Loop</SPAN><br>                <SPAN style="color:#00007F">Close</SPAN> #1<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN> Category<br>    <br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br>    <br>    MsgBox "Completed...", vbInformation<br>                    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
Domenic,

That is Awesome! thank you!! That will save a lot of copy and paste time!!
Have a followup question. In my haste to remove private date I forgot to mention that under the categories ie: Quad, Triple, Double, and Single there is a subset to the Level column, that could be 6 possibilities, ie; Beginner, intermediate, 2nd intermediate, mid intermediate, Lower Top, High Top, is it possible to have the 6 subcategories popped into a new Separate column, while still maintaining referential integrity? Lastly the file sent always has one extra column that they (client) use, is it possible to have the macro auto delete that last column?

Thank You!
 
Upvote 0
Domenic,

That is Awesome! thank you!! That will save a lot of copy and paste time!!

You're very welcome!

Have a followup question. In my haste to remove private date I forgot to mention that under the categories ie: Quad, Triple, Double, and Single there is a subset to the Level column, that could be 6 possibilities, ie; Beginner, intermediate, 2nd intermediate, mid intermediate, Lower Top, High Top, is it possible to have the 6 subcategories popped into a new Separate column, while still maintaining referential integrity? Lastly the file sent always has one extra column that they (client) use, is it possible to have the macro auto delete that last column?

Thank You!

For clarity, can you post a small sample of the data, along with the expected results?
 
Upvote 0
This is the revised sheet as received
Excel Workbook
ABCD
1LEVEL of AttainmentNational Office RegionName Upper and LowerRanking Position & Dollar Amount #1
2Quadruple:
3BeginnerNorth District, ILAlbert Einstein#2 - Percent of Increase 6.0%
4BeginnerNorth District, ILAlbert Einstein#2 - Dollar Increase $2,745
5BeginnerNorth District, ILAlbert Einstein#2 New Members 10
6BeginnerNorth District, ILAlbert Einstein#1 Member Renewals 16
72nd intermediateSouth Valley District, ILTony Tgier#1 NM 105.56%
82nd intermediateSouth Valley District, ILTony Tgier#1 - Percent of Increase 15.6%
92nd intermediateSouth Valley District, ILTony Tgier#1 - Dollar Increase $9,737
102nd intermediateSouth Valley District, ILTony Tgier#2 Member Renewals 14
11LowerTopCentral District, ILCarter Mann#2 - Percent of Increase 4.9%
12LowerTopCentral District, ILCarter Mann#6 - Dollar Increase $1,045
13LowerTopCentral District, ILCarter Mann#1 New Members 2
14LowerTopCentral District, ILCarter Mann#2 Member Renewals 5
15Additional People and data continues Down
Sheet1
#VALUE!
Excel 2000 Thank you!
 
Upvote 0
Your results don't seem to jive with the source data. In any case, it looks like you probably want to replace...

<font face=Calibri><SPAN style="color:#00007F">Open</SPAN> strPath & Category & ".csv" <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Output</SPAN> <SPAN style="color:#00007F">As</SPAN> #1<br>    <SPAN style="color:#00007F">Write</SPAN> #1, "National Office Region";<br>    <SPAN style="color:#00007F">Write</SPAN> #1, "Name Upper and Lower";<br>    <SPAN style="color:#00007F">Write</SPAN> #1, "Ranking Position & Dollar Amount #1";<br>    <SPAN style="color:#00007F">Write</SPAN> #1, "Ranking Position & Dollar Amount #2";<br>    <SPAN style="color:#00007F">Write</SPAN> #1, "Ranking Position & Dollar Amount #3";<br>    <SPAN style="color:#00007F">Write</SPAN> #1, "Ranking Position & Dollar Amount #4"<br>    <SPAN style="color:#00007F">Set</SPAN> Cell = FoundCell.Offset(1, 0)<br>    <SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">While</SPAN> Cell <> ""<br>        LastColumn = Cells(Cell.Row, Columns.Count).End(xlToLeft).Column<br>        <SPAN style="color:#00007F">For</SPAN> i = 2 <SPAN style="color:#00007F">To</SPAN> LastColumn<br>            <SPAN style="color:#00007F">If</SPAN> i <> LastColumn <SPAN style="color:#00007F">Then</SPAN><br>                <SPAN style="color:#00007F">Write</SPAN> #1, Cells(Cell.Row, i).Value;<br>            <SPAN style="color:#00007F">Else</SPAN><br>                <SPAN style="color:#00007F">Write</SPAN> #1, Cells(Cell.Row, i).Value<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>        <SPAN style="color:#00007F">Next</SPAN> i<br>        <SPAN style="color:#00007F">Set</SPAN> Cell = Cell.Offset(1, 0)<br>    <SPAN style="color:#00007F">Loop</SPAN><br><SPAN style="color:#00007F">Close</SPAN> #1<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN></FONT>

with

<font face=Calibri><SPAN style="color:#00007F">Open</SPAN> strPath & Category & ".csv" <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Output</SPAN> <SPAN style="color:#00007F">As</SPAN> #1<br>    <SPAN style="color:#00007F">Write</SPAN> #1, "LEVEL of Attainment";<br>    <SPAN style="color:#00007F">Write</SPAN> #1, "National Office Region";<br>    <SPAN style="color:#00007F">Write</SPAN> #1, "Name Upper and Lower";<br>    <SPAN style="color:#00007F">Write</SPAN> #1, "Ranking Position & Dollar Amount #1";<br>    <SPAN style="color:#00007F">Write</SPAN> #1, "Ranking Position & Dollar Amount #2";<br>    <SPAN style="color:#00007F">Write</SPAN> #1, "Ranking Position & Dollar Amount #3";<br>    <SPAN style="color:#00007F">Write</SPAN> #1, "Ranking Position & Dollar Amount #4"<br>    <SPAN style="color:#00007F">Set</SPAN> Cell = FoundCell.Offset(1, 0)<br>    <SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">While</SPAN> Cell <> ""<br>        LastColumn = Cells(Cell.Row, Columns.Count).End(xlToLeft).Column<br>        <SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> LastColumn<br>            <SPAN style="color:#00007F">If</SPAN> i <> LastColumn <SPAN style="color:#00007F">Then</SPAN><br>                <SPAN style="color:#00007F">Write</SPAN> #1, Cells(Cell.Row, i).Value;<br>            <SPAN style="color:#00007F">Else</SPAN><br>                <SPAN style="color:#00007F">Write</SPAN> #1, Cells(Cell.Row, i).Value<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>        <SPAN style="color:#00007F">Next</SPAN> i<br>        <SPAN style="color:#00007F">Set</SPAN> Cell = Cell.Offset(1, 0)<br>    <SPAN style="color:#00007F">Loop</SPAN><br><SPAN style="color:#00007F">Close</SPAN> #1<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN></FONT>

Which column do you wish to delete? Is it the last column from the source file? In your example, you refer to the last column of the .csv file, so I'm a little confused.
 
Upvote 0
Try adding the following line of code after "Application.ScreenUpdating = False"...

Code:
Columns("E").ClearContents
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

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