Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi -
I'm trying to seperate out repeating info (last column has unique data) and place them into a new line. For example: 12345 CBB 12345 GGG 54321 PPP 99999 BBB 99999 AXZ Would turn into 12345 CBB GGG 54321 PPP 99999 BBB AXZ I've been trying to do this through a macro by reading in every row and matching if the first column matches the second column then take whats in the first column and place into the last column then delete the first row. But I havn't found a great way in code to do this yet. My first problem is that I can't determine how many times the number would repeat so I don't know how many columns to go over etc... Thanks for any help on this, - Tek |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try this
Sub Test() Dim myCell As Range Dim aWS As Worksheet Dim lRow As Long Dim myDeleteRange As Range Set aWS = ActiveSheet lRow = aWS.Cells(aWS.Rows.Count, 1).End(xlUp).row Set myCell = aWS.Range("A1") '<~~~change first cell as needed Do If myCell.Offset(1, 0).Value = myCell.Value Then lcol = aWS.Cells(myCell.row, aWS.Columns.Count).End(xlToLeft).Column + 1 myCell.Offset(0, lcol - myCell.Column).Value = myCell.Offset(1, 1).Value If myDeleteRange Is Nothing Then Set myDeleteRange = myCell.Offset(1, 0) Else Set myDeleteRange = Union(myDeleteRange, myCell.Offset(1, 0)) End If End If Set myCell = myCell.Offset(1, 0) Loop While myCell.row < lRow If Not myDeleteRange Is Nothing Then Debug.Print myDeleteRange.Address myDeleteRange.EntireRow.Delete End If End Sub -- HTH, Barb Reinhardt If this post was helpful to you, please click YES below. " wrote: Hi - I'm trying to seperate out repeating info (last column has unique data) and place them into a new line. For example: 12345 CBB 12345 GGG 54321 PPP 99999 BBB 99999 AXZ Would turn into 12345 CBB GGG 54321 PPP 99999 BBB AXZ I've been trying to do this through a macro by reading in every row and matching if the first column matches the second column then take whats in the first column and place into the last column then delete the first row. But I havn't found a great way in code to do this yet. My first problem is that I can't determine how many times the number would repeat so I don't know how many columns to go over etc... Thanks for any help on this, - Tek |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Barb - thanks for your marco. But it does not work if you have more than 2
repeating values in the first column. 12345 CBB 12345 XXX 12345 HHH 54321 PPP 99999 BBB 99999 AXZ "Barb Reinhardt" wrote: Try this Sub Test() Dim myCell As Range Dim aWS As Worksheet Dim lRow As Long Dim myDeleteRange As Range Set aWS = ActiveSheet lRow = aWS.Cells(aWS.Rows.Count, 1).End(xlUp).row Set myCell = aWS.Range("A1") '<~~~change first cell as needed Do If myCell.Offset(1, 0).Value = myCell.Value Then lcol = aWS.Cells(myCell.row, aWS.Columns.Count).End(xlToLeft).Column + 1 myCell.Offset(0, lcol - myCell.Column).Value = myCell.Offset(1, 1).Value If myDeleteRange Is Nothing Then Set myDeleteRange = myCell.Offset(1, 0) Else Set myDeleteRange = Union(myDeleteRange, myCell.Offset(1, 0)) End If End If Set myCell = myCell.Offset(1, 0) Loop While myCell.row < lRow If Not myDeleteRange Is Nothing Then Debug.Print myDeleteRange.Address myDeleteRange.EntireRow.Delete End If End Sub -- HTH, Barb Reinhardt If this post was helpful to you, please click YES below. " wrote: Hi - I'm trying to seperate out repeating info (last column has unique data) and place them into a new line. For example: 12345 CBB 12345 GGG 54321 PPP 99999 BBB 99999 AXZ Would turn into 12345 CBB GGG 54321 PPP 99999 BBB AXZ I've been trying to do this through a macro by reading in every row and matching if the first column matches the second column then take whats in the first column and place into the last column then delete the first row. But I havn't found a great way in code to do this yet. My first problem is that I can't determine how many times the number would repeat so I don't know how many columns to go over etc... Thanks for any help on this, - Tek |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Barb -
Thanks for the response! This is pretty close, but it indeed only worked if you only have 2 repeating rows otherwise it strips off the third row. Although I'm going to see if I can't figure out a way to fix it using the code you posted. Thanks, - Tek |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Seperate info in a cell | Excel Worksheet Functions | |||
Repeating Info Change | Excel Discussion (Misc queries) | |||
HOW DO I SEPERATE INFO FROM ONE INTO TWO COLUMNS? | Excel Worksheet Functions | |||
Repeating Characters in Cells with info. | Excel Discussion (Misc queries) | |||
How do I remove repeating line in Excell - Top line on each page.. | Excel Worksheet Functions |