Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default I'd like to put multiple rows in one CSV row

I've got a table that looks like this:
017-2032 24
017-2032 30
017-2032 49
017-2032 315
017-2095 30
017-2095 49
017-2095 24
017-2095 315
017-2096 24
017-2096 315
017-4246 315
017-4246 24
017-4246 30
017-4246 49
024-3308 305
024-3308 304

And I'd like to make it look like this:

017-2032 24,30,49,315
017-2095 30,49,24,315
017-2096 24,315
017-4246 315,24,30,49
024-3308 305,304


How can I do that? I'm really bad at this kind of stuff :(

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default I'd like to put multiple rows in one CSV row

Is the row "identifier" always of the format xxx-xxxx or could it contain more or fewer characters?

--
Tim Williams
Palo Alto, CA


wrote in message oups.com...
I've got a table that looks like this:
017-2032 24
017-2032 30
017-2032 49
017-2032 315
017-2095 30
017-2095 49
017-2095 24
017-2095 315
017-2096 24
017-2096 315
017-4246 315
017-4246 24
017-4246 30
017-4246 49
024-3308 305
024-3308 304

And I'd like to make it look like this:

017-2032 24,30,49,315
017-2095 30,49,24,315
017-2096 24,315
017-4246 315,24,30,49
024-3308 305,304


How can I do that? I'm really bad at this kind of stuff :(



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default I'd like to put multiple rows in one CSV row

Hi Kyle:

Try:

Sub condensetable()

'assume the cursor is in the first cell on the left
Dim r As Range 'firstcell
Set r = ActiveCell
Dim rOffset As Long ' current row offset
rOffset = 1 ' start on second row
Do While r.Offset(rOffset, 0) < ""
If (r.Offset(rOffset, 0) = r.Offset(rOffset - 1, 0)) Then
r.Offset(rOffset - 1, 1) = _
r.Offset(rOffset - 1, 1) & ", " & _
r.Offset(rOffset, 1)
r.Offset(rOffset, 0).EntireRow.Delete
Else
rOffset = rOffset + 1
End If
Loop
End Sub

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


" wrote:

I've got a table that looks like this:
017-2032 24
017-2032 30
017-2032 49
017-2032 315
017-2095 30
017-2095 49
017-2095 24
017-2095 315
017-2096 24
017-2096 315
017-4246 315
017-4246 24
017-4246 30
017-4246 49
024-3308 305
024-3308 304

And I'd like to make it look like this:

017-2032 24,30,49,315
017-2095 30,49,24,315
017-2096 24,315
017-4246 315,24,30,49
024-3308 305,304


How can I do that? I'm really bad at this kind of stuff :(


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default I'd like to put multiple rows in one CSV row

One way:

Option Explicit
Sub testme()
Dim wks As Worksheet
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long

Set wks = Worksheets("sheet1")

With wks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = LastRow To FirstRow + 1 Step -1
If .Cells(iRow, "A").Value = .Cells(iRow - 1, "A").Value Then
.Cells(iRow - 1, "B").Value _
= "'" & .Cells(iRow - 1, "B").Value _
& "," & .Cells(iRow, "B").Value
.Rows(iRow).Delete
End If
Next iRow
End With

End Sub

Be careful.

This routine destroys the original data--run it against a backup copy of your
worksheet--or close without saving if you don't get the results you want.

The "'" forces the stuff in column B to be treated as text. I didn't want excel
changing the underlying value to a plain old number.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm




wrote:

I've got a table that looks like this:
017-2032 24
017-2032 30
017-2032 49
017-2032 315
017-2095 30
017-2095 49
017-2095 24
017-2095 315
017-2096 24
017-2096 315
017-4246 315
017-4246 24
017-4246 30
017-4246 49
024-3308 305
024-3308 304

And I'd like to make it look like this:

017-2032 24,30,49,315
017-2095 30,49,24,315
017-2096 24,315
017-4246 315,24,30,49
024-3308 305,304

How can I do that? I'm really bad at this kind of stuff :(


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hpw do I delete multiple empty rows found between filled rows? Bill Excel Worksheet Functions 2 November 15th 09 07:12 PM
Counting characters in multiple rows when rows meet specific criteria news.virginmedia.com Excel Worksheet Functions 3 June 28th 08 09:03 PM
Delete Blank Rows Code - Multiple Worksheets - Multiple Documents BenS Excel Discussion (Misc queries) 3 June 29th 07 12:20 AM
Copying multiple rows to other worksheets (but amount of rows varies) - How? David Smithz Excel Discussion (Misc queries) 1 June 18th 06 04:31 PM
Inserting multiple rows in excel with data in consecutive rows technotronic Excel Programming 2 October 20th 05 03:12 PM


All times are GMT +1. The time now is 05:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"