+ Reply to Thread
Results 1 to 8 of 8

Excel Macro to create Header and lines and save with Pipe CSV format

Hybrid View

  1. #1
    Registered User
    Join Date
    11-21-2017
    Location
    SYDNEY
    MS-Off Ver
    2016
    Posts
    36

    Re: Excel Macro to create Header and lines and save with Pipe CSV format

    Hello Karedog,

    there is a slight change to this file and I've tried making it in this file but was unsuccessful in changing the code. can you please help? I've attached a new version of the file and highlighted the row.

    i get an error on 'z(strKey)(4).Add Array(a(i, 2), a(i, 3), a(i, 7))' I've moved the cols across but not sure why.



    Sub Test()
      Const outputFilename As String = "Test.csv"
      Const c1  As String = "XXXX"
      Dim a, d, i As Long, strKey As String, strResult As String, v1, v2, z As New Collection
      With Sheets("Sheet1")
        d = .Range("B1:B3").Value
        a = .Range("A5").CurrentRegion.Value
      End With
      For i = 2 To UBound(a, 1)
          strKey = a(i, 1)
          On Error Resume Next
             z.Add key:=strKey, Item:=Array(a(i, 1), a(i, 4), a(i, 5), a(i, 6), New Collection)
          On Error GoTo 0
          z(strKey)(4).Add Array(a(i, 2), a(i, 3), a(i, 7))
      Next i
      For Each v1 In z
          strResult = strResult & "H|" & c1 & "|" & v1(1) & "|AA|00|XXXX|||" & v1(2) & "||" & v1(3) & "|" & d(2, 1) & "|" & d(3, 1) & vbCrLf
          For Each v2 In v1(4)
              strResult = strResult & "I|" & v2(0) & "|" & v2(1) & "|" & d(1, 1) & "||" & v2(2) & vbCrLf
          Next v2
      Next v1
      i = FreeFile
      Open ThisWorkbook.Path & "\" & outputFilename For Output As #i
        Print #i, strResult
      Close #i
    End Sub
    o
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to create txt-file with pipe seperator
    By elgato74 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-27-2017, 09:22 AM
  2. Macro needed to save file in pipe delimited format
    By Blaked86 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-04-2014, 09:04 AM
  3. Macro to open multiple files, remove header and save multiple files in a new format
    By twocircles in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-17-2014, 05:24 PM
  4. Combine Excel Sheets (+2 Million Rows total) and Create Pipe Delimited TEXT File
    By kestefon in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-05-2013, 08:51 PM
  5. need macro to create pipe delimited text file from excel
    By nefkho in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-04-2012, 12:03 PM
  6. How to save an excel in a pipe delimited format?
    By princesouvik in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-08-2009, 03:13 AM
  7. Replies: 5
    Last Post: 05-25-2006, 03:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1