Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default HELP: Formula for combining fields


Can someone help me ?

I have a CSV file which can be opened in Excel. The CSV file i
comma-seperated !

Column 1 contains the cd numbers and column 2 contains the tracknumber
and names

So I do have a table with the following contents:
1,01;track1
1,02;track2
1,03;track3
2,02;track1
2,02;track2
And so on....

I want to have a formula, or result with the following contents:
1,01;track1|02;track2|03;track3
2,02;track1|02;track2

Is that possible to create ? How

--
pollewop
-----------------------------------------------------------------------
pollewops's Profile: http://www.excelforum.com/member.php...fo&userid=3399
View this thread: http://www.excelforum.com/showthread.php?threadid=53762

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Formula for combining fields

Assume you open the sheet in excel and it appears as

Column A Column B
1 01;track1
1 02;track2
1 03;track3

And you want

Column A Column B Column C Column D
1 01;track1 02;track2 03;track3

Sub ProcessCSVFile()
Dim fname as Variant
Dim sh as Worksheet, sh1 as Worksheet
Dim rng as Range, i as Long, j as Long

fname = Application.GetOpenFilename(FileFilter:="CSV Files (*.CSV),*.CSV")
if fName = False then
exit sub
end if
set bk = Workbooks.Open(fName)

Set sh = ActiveSheet
With sh
Set rng = .Range(.Cells(1, 2), .Cells(Rows.Count, 2).End(xlUp))
EndWith
Set sh1 = Worksheets.Add(After:=Worksheets(Worksheets.Count) )
i = 1
j = 2
sh1.Cells(i, 1) = rng(1, 0).Value
For Each cell In rng
sh1.Cells(i, j) = cell.Value
If cell(1, 0).Value < cell(2, 0).Value Then
i = i + 1
j = 2
sh1.Cells(i, 1).Value = cell(2, 0).Value
Else
j = j + 1
End If
Next
Application.DisplayAlerts = False
sh.delete
Application.DisplayAlerts = true
End Sub

--
Regards,
Tom Ogilvy



"pollewops" wrote
in message ...

Can someone help me ?

I have a CSV file which can be opened in Excel. The CSV file is
comma-seperated !

Column 1 contains the cd numbers and column 2 contains the tracknumbers
and names

So I do have a table with the following contents:
1,01;track1
1,02;track2
1,03;track3
2,02;track1
2,02;track2
And so on....

I want to have a formula, or result with the following contents:
1,01;track1|02;track2|03;track3
2,02;track1|02;track2

Is that possible to create ? How ?


--
pollewops
------------------------------------------------------------------------
pollewops's Profile:

http://www.excelforum.com/member.php...o&userid=33999
View this thread: http://www.excelforum.com/showthread...hreadid=537625



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default HELP: Formula for combining fields

You seem to have 3 delimeters on your 'desired' rendering of your data comma,
semi-colon and pipe. (?).

Depending on the size of your CSV file, you might want to rewrite its
content to another file in the desired format and that that file instead:

Sub aa()
Close
FtieIn = FreeFile
Open "c:\zz.csv" For Input As #FtieIn
Ftieout = FreeFile
Open "c:\zz2.csv" For Output As #Ftieout
REC = "0"
Line = ""
Do Until EOF(FtieIn)
Line Input #FtieIn, a
If REC = Left(a, InStr(a, ",") - 1) Then
If a = Line Then
Line = Line
Else
Line = Line & "," & Mid(a, 2 + Len(REC))
End If
Else
If 0 < Len(Line) Then
Print #Ftieout, Line
Debug.Print Line
End If
REC = Left(a, InStr(a, ",") - 1) ' , is your record delimiter
Line = a
End If
Loop
Print #Ftieout, Line
Debug.Print Line
Close
End Sub

The Debug.Print (also written to the out file) produces:
1,01;track1,02;track2,03;track3
2,02;track1,02;track2

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
Combining spread sheets with common fields jjacksonn1966 Excel Discussion (Misc queries) 3 September 12th 08 04:27 PM
Drop down selections and combining fields. JaneAnderson New Users to Excel 3 October 10th 06 04:48 AM
combining fields on a pivot table [email protected] Excel Worksheet Functions 1 July 12th 06 12:53 AM
Combining fields and outputting to one cell Doug[_12_] Excel Programming 2 January 6th 05 11:28 PM
Commenting custom formula fields/formula on formula editor Muxer Excel Programming 2 July 24th 03 01:02 AM


All times are GMT +1. The time now is 07:46 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"