ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to sort through data (https://www.excelbanter.com/excel-programming/358780-macro-sort-through-data.html)

systemx[_11_]

Macro to sort through data
 

Hi all,

I was wandering if anyone can offer any advice on a problem.

Basically, in A:A I have a list of numbers. In B:B I have a list of
corresponding values. The values in B:B are always unique, but values
in A:A may be the same. Identical values will always appear together
(eg A1, A2, A3, etc).

I want to make a macro to sort through this data, and if A1=A2, copy B2
to C1. If A1=A3, copy B3 to A1.

Then move down the list in A:A until it finds the next value....and
repeat.

So in essence...where values in A:A are identical, column B:B is copied
and then transposed into the first cell containing the value.

If this does not make sense...the diagram below may help explain!

Original list -

A B
1 569
1 572
2 433
3 625
4 744
5 766
5 767
5 792

Sorted List -

A B C D
1 569 572
1 572
2 433
3 625
4 744
5 766 767 792
5 767
5 792

Thank you in advance for any advice!

Robert :confused:


--
systemx
------------------------------------------------------------------------
systemx's Profile: http://www.excelforum.com/member.php...o&userid=29254
View this thread: http://www.excelforum.com/showthread...hreadid=532528


Greg Wilson

Macro to sort through data
 
Try:

Sub TransposeRepeats()
Dim r As Range
Dim ws As Worksheet
Dim i As Integer, ii As Integer

Set ws = Sheets("Sheet1")
Set r = ws.Range(ws.Cells(2, 1), _
ws.Cells(2, 1).End(xlDown))
With Application
.ScreenUpdating = False
For i = 1 To r.Count
ii = 1
Do Until r(i + ii) < r(i)
ii = ii + 1
Loop
If ii 1 Then
r(i, 2).Resize(1, ii) = _
.Transpose(r(i, 2).Resize(ii, 1))
i = i + ii - 1
End If
Next
.ScreenUpdating = True
End With
End Sub

Change ws name and ranges to suit.

Regards,
Greg


"systemx" wrote:


Hi all,

I was wandering if anyone can offer any advice on a problem.

Basically, in A:A I have a list of numbers. In B:B I have a list of
corresponding values. The values in B:B are always unique, but values
in A:A may be the same. Identical values will always appear together
(eg A1, A2, A3, etc).

I want to make a macro to sort through this data, and if A1=A2, copy B2
to C1. If A1=A3, copy B3 to A1.

Then move down the list in A:A until it finds the next value....and
repeat.

So in essence...where values in A:A are identical, column B:B is copied
and then transposed into the first cell containing the value.

If this does not make sense...the diagram below may help explain!

Original list -

A B
1 569
1 572
2 433
3 625
4 744
5 766
5 767
5 792

Sorted List -

A B C D
1 569 572
1 572
2 433
3 625
4 744
5 766 767 792
5 767
5 792

Thank you in advance for any advice!

Robert :confused:


--
systemx
------------------------------------------------------------------------
systemx's Profile: http://www.excelforum.com/member.php...o&userid=29254
View this thread: http://www.excelforum.com/showthread...hreadid=532528




All times are GMT +1. The time now is 02:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com