Formatting problem

chadski778

Active Member
Joined
Mar 14, 2010
Messages
297
In my table I have multiple rows where the value in column A and column M is the same but the values in column AM are different. I would like the different values in AM to be added to the end of the top row and then the duplicate lines deleted. It is easier to understand by looking at the spreadsheet. Can this be done? It is simple reformatting but very labour intensive because there are about 1500 lines in the table.

Excel Workbook
AMAMANAOAPAQARASATAUAVAWAXAY
1COLUMN ACOLUMN MCOLUMN AMCOLUMN ACOLUMN MCOLUMN AMCOLUMN APCOLUMN AQCOLUMN ARCOLUMN ASCOLUMN ATCOLUMN AU
2GPC CodeFORM CODESP NAMEGPC CodeFORM CODESP NAME
3140001760898140003430573ATF 134 FE140001760898140003430573ATF 134 FEMB ATF 134 FE
4140001760898140003430573MB ATF 134 FE?140001786620140002274173FormulaShell Automatic Transmission FluidPremium Choice Automatic Transmission FluidPzl Automatic Transmission FluidQS Automatic Transmission FluidTurbo Automatic Transmission Fluid
5140001786620140002274173FormulaShell Automatic Transmission Fluid140001957448140002396580Advance 4T 5W-30 (SF)Advance 4T AX3 Cold Start 5W-30 (SG/MA)
6140001786620140002274173Premium Choice Automatic Transmission Fluid140001958754140002055102Donax TX (USA/Can/Mex)
7140001786620140002274173Pzl Automatic Transmission Fluid140001958754140002252221ATF 134MB ATF 134
8140001786620140002274173QS Automatic Transmission Fluid140001958754140003430573ATF 134 FEMB ATF 134 FE
9140001786620140002274173Turbo Automatic Transmission Fluid
10140001957448140002396580Advance 4T 5W-30 (SF)
11140001957448140002396580Advance 4T AX3 Cold Start 5W-30 (SG/MA)
12140001958754140002055102Donax TX (USA/Can/Mex)
13140001958754140002252221ATF 134
14140001958754140002252221MB ATF 134
15140001958754140003430573ATF 134 FE
16140001958754140003430573MB ATF 134 FE
17
Sheet1


Thanks

Chad
 
Excel Workbook
AMALAMANAO
1
2BEFORE
3
4GPC CodeFORM CODESP CODESP NAMESP STATUSSP OWNER
5GB100604140003442737001E2256Advance 4T AJ 10W-30 for Astra (SL/MA)Active - GenericMR A
6GB100604140003442737001D8579Advance 4T AX5 10W-30 (SL/MA)Active - GenericMR B
7GB100604140002102369228C8511Suzuki ATV Synthetic Blend 5W-30 (SJ, MA)Active - Customer specificMR C
8140001957448140002396580001B1714Advance 4T 5W-30 (SF)To be deletedMR D
9140001957448140002396580001E1157Advance 4T AX3 Cold Start 5W-30 (SG/MA)Active - GenericMR E
10GB100562140002088852001C7857MotoMaster Formula1 10W-40 Motorcycle Oil(SJ/JASO MA)Active - Customer specificMR F
11GB100562140002088852001C7855MotoMaster Formula1 ATV 10W-40(SJ/JASO MA)Active - Customer specificMR G
12GB100562140002088852001C7430Suzuki Motorcycle Engine Oil SAE 10W40 (SJ, MA)Active - Customer specificMR H
13
14
C-F-SP (2)



Excel Workbook
AMALAMANAOAPAQARASATAUAVAW
1
2AFTER
3
4GPC CodeFORM CODESP CODESP NAMESP STATUSSP OWNERSP CODE 1SP NAME 1SP STATUS 1SP OWNER 1SP CODE 2SP NAME 2SP STATUS 2SP OWNER 2
5GB100604140003442737001E2256Advance 4T AJ 10W-30 for Astra (SL/MA)Active - GenericMR A001D8579Advance 4T AX5 10W-30 (SL/MA)Active - GenericMR B
6GB100604140002102369228C8511Suzuki ATV Synthetic Blend 5W-30 (SJ, MA)Active - Customer specificMR C
7140001957448140002396580001B1714Advance 4T 5W-30 (SF)To be deletedMR D001E1157Advance 4T AX3 Cold Start 5W-30 (SG/MA)Active - GenericMR E
8GB100562140002088852001C7857MotoMaster Formula1 10W-40 Motorcycle Oil(SJ/JASO MA)Active - Customer specificMR F001C7855MotoMaster Formula1 ATV 10W-40(SJ/JASO MA)Active - GenericMR G001C7430Suzuki Motorcycle Engine Oil SAE 10W40 (SJ, MA)Active - Customer specificMR H
9
10
11
12
C-F-SP



It doesn't matter about the new column headings I can always put them in later.
Thanks
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try this

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> Rearrange()<br>    <SPAN style="color:#00007F">Dim</SPAN> lr <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, r <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, c <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    <SPAN style="color:#00007F">Const</SPAN> Cols <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN> = 4 <SPAN style="color:#007F00">'<- Cols AL:AO</SPAN><br>    <br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>    lr = Range("A" & Rows.Count).End(xlUp).Row<br>    <SPAN style="color:#00007F">For</SPAN> r = lr <SPAN style="color:#00007F">To</SPAN> 5 <SPAN style="color:#00007F">Step</SPAN> -1<br>        <SPAN style="color:#00007F">If</SPAN> Cells(r, "A").Value = Cells(r - 1, "A").Value And _<br>                Cells(r, "M").Value = Cells(r - 1, "M").Value <SPAN style="color:#00007F">Then</SPAN><br>            c = c + 1<br>            Cells(r - 1, "AL").End(xlToRight).Offset(, 1).Resize(, c * Cols) _<br>                .Value = Cells(r, "AL").Resize(, c * Cols).Value<br>            Rows(r).Delete<br>        <SPAN style="color:#00007F">Else</SPAN><br>            c = 0<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN> r<br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><br><br></FONT>
 
Upvote 0
The first thing to say is it works! Thak you very much.
The extra problem I have is that the columns of data that are required to be rearranged will not always be in the same columns

In my data:
Col Name Col headings
Col A = GPC Code
Col M = FORM CODE
Col AL = SP CODE
Col AM = SP NAME
Col AN = SP STATUS
Col AO = SP OWNER

Is there a way of carrying out the same exercise using the column headings so that the column names are irrelevant?
 
Upvote 0
The first thing to say is it works! Thak you very much.
The extra problem I have is that the columns of data that are required to be rearranged will not always be in the same columns

In my data:
Col Name Col headings
Col A = GPC Code
Col M = FORM CODE
Col AL = SP CODE
Col AM = SP NAME
Col AN = SP STATUS
Col AO = SP OWNER

Is there a way of carrying out the same exercise using the column headings so that the column names are irrelevant?
Provided the "SP CODE", "SP NAME", "SP STATUS" & "SP OWNER" columns are consecutive columns, then try this modification.

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> Rearrange2()<br>    <SPAN style="color:#00007F">Dim</SPAN> lr <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, r <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, c <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> cGPC <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, cForm <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, cSPC <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    <SPAN style="color:#00007F">Const</SPAN> HeaderRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN> = 4 <SPAN style="color:#007F00">'<- Change to suit your header row</SPAN><br>    <SPAN style="color:#00007F">Const</SPAN> Cols <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN> = 4      <SPAN style="color:#007F00">'<- No. of columns to move</SPAN><br>    <br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>    <SPAN style="color:#00007F">With</SPAN> Rows(HeaderRow)<br>        cGPC = .Find(What:="GPC Code", LookIn:=xlValues, LookAt:=xlWhole, _<br>            MatchCase:=False, SearchFormat:=False).Column<br>        cForm = .Find(What:="Form Code", LookIn:=xlValues, LookAt:=xlWhole, _<br>            MatchCase:=False, SearchFormat:=False).Column<br>        cSPC = .Find(What:="SP Code", LookIn:=xlValues, LookAt:=xlWhole, _<br>            MatchCase:=False, Search<SPAN style="color:#00007F">For</SPAN>mat:=False).Column<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    lr = Cells(Rows.Count, cGPC).End(xlUp).Row<br>    For r = lr <SPAN style="color:#00007F">To</SPAN> HeaderRow + 2 <SPAN style="color:#00007F">Step</SPAN> -1<br>        <SPAN style="color:#00007F">If</SPAN> Cells(r, cGPC).Value = Cells(r - 1, cGPC).Value And _<br>                Cells(r, cForm).Value = Cells(r - 1, cForm).Value <SPAN style="color:#00007F">Then</SPAN><br>            c = c + 1<br>            Cells(r - 1, cSPC).End(xlToRight).Offset(, 1).Resize(, c * Cols) _<br>                .Value = Cells(r, cSPC).Resize(, c * Cols).Value<br>            Rows(r).Delete<br>        <SPAN style="color:#00007F">Else</SPAN><br>            c = 0<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN> r<br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br></FONT>
 
Upvote 0
Thanks for all the help you have given me, I really appreciate it. I can envisage getting similar problems at work with slight variations on the data. I need to build up a library of possible scenarios and solutions. If I have a problem similar to the ones you have helped me with shall I post a reply from this message chain?

Thanks again

Chad
 
Upvote 0
If I have a problem similar to the ones you have helped me with shall I post a reply from this message chain?
It depends on how similar the next problem is.

If it is very similar, you could post in this thread and explain the slight variation.

If it is only slightly similar then I would suggest starting a new thread and perhaps add a link to this thread from your new thread if you think potential helpers would gain understanding about your new problem by being aware of this thread.
 
Upvote 0

Forum statistics

Threads
1,224,540
Messages
6,179,417
Members
452,912
Latest member
alicemil

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