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 Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try this in a copy of your workbook. I wasn't sure if you really wanted the first result to stay in column AM and the second one to be in column AP (that is to skip 2 columns). If you do, uncomment the the line near the end of the code.

I have assumed your data is already sorted by columns A and then M per your sample data.

<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>    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> 2 <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, "AN").Resize(, c).Value = _<br>                Cells(r, "AM").Resize(, c).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><SPAN style="color:#007F00">'    Columns("AN:AO").Insert '<- Not sure about this</SPAN><br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
Thanks I think we're nearly there.

I want the first result to stay in column AM and the second to be in column AP and the third AQ etc (skips two columns). At present the second result is landing in AN and the third in AO etc even when i take out the green bit of code at the end?
 
Upvote 0
Thanks I think we're nearly there.

I want the first result to stay in column AM and the second to be in column AP and the third AQ etc (skips two columns). At present the second result is landing in AN and the third in AO etc even when i take out the green bit of code at the end?
I did not suggest you take out the green code, I suggested that you uncomment it. That is, remove the ' from the beginning of the line.

The ' means to treat the line as a comment, so it performs no action as it stood in my code. Removing the line altogether changes nothing.

If you re-insert that line but remove the ' at the start of the line (don't remove the other one towards the end of the line because what follows that really is a comment) then that line should insert 2 new columns, making the second result move to column AP.
 
Last edited:
Upvote 0
The macro seems to be shifting the contents of the columns AN and AO by two columns to the right. I would like AN and AO to be untouched. Is there any way that the duplicates in coulumn AM can be moved to AP, AQ, AR, AS, AT etc without moving anything from columns AN and AO? Other than that it looks like it is working.

Many thanks for your time and effort. It's looking good
 
Upvote 0
Before the code is run, where do you have data in columns AN and AO?
Presumably it is the moving of this data that is the problem with my current code?
Is it in the rows we are dealing with or above/below that data area?
 
Upvote 0
Perhaps my previous questions are irrelevant. Try this version.

<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>    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> 2 <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>            Cells(r - 1, "AP").Value = _<br>                    Cells(r, "AM").Value<br>            c = c + 1<br>            <SPAN style="color:#00007F">If</SPAN> c > 1 <SPAN style="color:#00007F">Then</SPAN><br>                Cells(r - 1, "AQ").Resize(, c - 1).Value = _<br>                    Cells(r, "AP").Resize(, c - 1).Value<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><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></FONT>
 
Upvote 0
The last macro worked brilliantly, thanks. Now I need it tweaked a little bit. It's the same conditions as before but now if there are duplicates in A & M but not in AM I need the contents of columns AL, AM, AN and AO to move to AP, AQ, AR and AS keeping the same order. If there is more than 1 duplicate they need to move to AT, AU, AV and AW etc and the duplicates deleted as before. I've tried to tweak it but it's not working.
 
Upvote 0
Any chance of another small set of sample data and expected results to demonstreate this new requirement?

Instead of putting the original data and the results in separate sections of the same sheet (column headings became a bit confusing) just post 2 screen shots (Before and After) with everything in their correct columns/rows. You should still hide the irrelevat columns.
 
Upvote 0

Forum statistics

Threads
1,224,532
Messages
6,179,388
Members
452,908
Latest member
MTDelphis

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