• Ask a Question
150
Insert Image Size must be less than < 5MB.
    Ask a Question
    Cancel
    150
    More answer You can create 5 answer(s).
      Ask a Poll
      Cancel
      Top Contributor

      create separate file for each row in Worksheet using VBA

      Hi, I am using this code to export each line item as a separate file, however I want the column headers to be constant, unable to do it, for instance I would like each file to have the column names but contain only the specific assignee information

      create separate file for each row in Worksheet using VBAsample file


      Sub ExportTextFiles()
      Dim i As Long
      Dim LastDataRow As Long
      Dim MyFile As String
      Dim fnum
      With ActiveSheet
      LastDataRow = .Range(“A” & Rows.Count).End(xlUp).Row
      lastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column
      End With
      For i = 2 To LastDataRow
      'The next line uses the contents of column B on the same row to name it
      MyFile = "C:\Users\pkc504787\Desktop\Client Work\Trifecta\test\" & ActiveSheet.Range("A" & i).Value & ".pdf"
      ' fnum = FreeFile()
      Open MyFile For Output As fnum
      'It reads all values from respective row
      For iCntr = 1 To lastColumn
      Print #1, Cells(i, iCntr)
      Next iCntr
      Close fnum
      Next i
      End Sub
      

      Asked by pranab79in on October 25, 2017 in VBA: Macros.
      1 Answers
      Expert

      What would you like to export exactly : PDF or TXT files?

      Can you upload sample of your workbook?

      Answered by YasserKhalil on October 27, 2017..
      • I would like it to be a PDF file. It should have the column headers and individual record captured in one file each. I don’t have a sample. Thank you once again for all your help.

        on October 31, 2017.
      • Sir-Any update regarding this will help

        on November 6, 2017.
      Cancel
      Add comment