Export xls data in csv format or tab delimited format

Hi All,

   I have written a macro that will help you export the data from your excel sheet to csv format or tab delimited format.

 

Column 1 Column 2 Column 3
Column 2 Column 3 Column 4
Column 3 Column 4 Column 5
Column 4 Column 5 Column 6
Column 5 Column 6 Column 7
Column 6 Column 7 Column 8
Column 7 Column 8 Column 9
Column 8 Column 9 Column 10
Column 9 Column 10 Column 11
Column 10 Column 11 Column 12
Column 11 Column 12 Column 13
Column 12 Column 13 Column 14
Column 13 Column 14 Column 15

 

Above is the data in excel and this data can be converted to tab limited csv format using the following macro code.

 Private Sub CommandButton1_Click()
'code written on 06/01/2009 by Pavandeep Puddupakkam
    Dim FileNum As Integer
    Dim LastRow As Long, LastCol As Integer, r As Long,
    
    
    LastRow = Sheet3.UsedRange.Rows(Sheet3.UsedRange.Rows.Count).Row
    LastCol = Sheet3.UsedRange.Columns(Sheet3.UsedRange.Columns.Count).Column
    
    FileNum = FreeFile ' next file number
    Open "C:\CSVFiles\CSVFILE.txt" For Output As #FileNum ' creates the file if it doesn't exist

For r = 1 To 13
     Print #FileNum, Cells(r, 1); "|"; Cells(r, 2); "|"; Cells(r, 3); "|"
          Print #FileNum,
           Next r
        
Close #FileNum ' close the file
End Sub

 

Submitted by Pavandeep Puddupakkam

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: wiki
Posted on: 5/31/2009 at 2:23 PM
Tags: , , , ,
Categories: VBA Macros
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (31) | Post RSSRSS comment feed

Comments

Add comment


 

  Country flag

biuquote
  • Comment
  • Preview
Loading