Transpose the data

aladin347

New Member
Joined
Sep 11, 2014
Messages
9
Hi Experts,

Could you please help me as how to transpose the data in the below format, by looking at the city or number and the below cells for the respective city should be blanks.



NOCityPO NoExample - Transpose
100AMERICA340643562559269
100AMERICA643
100AMERICA562
100AMERICA559
100AMERICA269
200London582775575705379
200London775
200London575
200London705
200London379
300JONARD776result with Formula
300JONARD430
300JONARD556
300JONARD409
300JONARD694

<tbody>
</tbody>

Thanks,
Aladdin
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi

If your city column is sorted as in your example, and your data is in column A, B and C then
try this formula in column D (cell D2). Confirm with Ctrl+Shift+Enter (it's an array formula). Adjust the ranges as needed.
Copy the formula to right as many columns as needed, and down all the rows.
=IF(COLUMNS($D$1:D1)>COUNTIF($B$2:$B$16,$B2),"",IF($B2<>$B1,LARGE(IF($B$2:$B$16=$B2,$C$2:$C$16),COLUMNS($D$1:D1)),""))
 
Upvote 0
this is one of the ways you could do it with vba as well

since i did not quite get what you meant by:

and the below cells for the respective city should be blanks.

i have added
Code:
.ClearContents

you can remove it if unnecessary

Code:
Sub Transpose_the_data()
Dim Arr, Ndx As Long, LRow As Long
Application.ScreenUpdating = False
LRow = Range("A" & Rows.Count).End(xlUp).Row
Arr = Filter(Evaluate(Replace(Replace("TRANSPOSE(IF(B2:B%<>B1:B@,ROW(B1:B@)+1,""°°°""))", "%", LRow + 1), "@", LRow)), "°°°", False)
For Ndx = LBound(Arr) To UBound(Arr) - 1
    With Range("C" & Arr(Ndx) + 1 & ":C" & Arr(Ndx + 1) - 1)
        .Copy
        Range("D" & Arr(Ndx)).PasteSpecial , , , True
        .ClearContents
    End With
Next
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,791
Members
449,095
Latest member
m_smith_solihull

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