How to copy first two columns from a Excel worksheet into a text file

Sanders_2503

New Member
Joined
Mar 29, 2012
Messages
2
Dear Experts,

I am converting a xls workbook into a tab delimited text file, but instead of copying the entire workbook, I want to copy the first two columns of the workbook except for the header row.

This is my code which is copying the entire workbook -


Code:
Private Sub SaveAsTabDelimited(ByVal sFileName As String)
  With ActiveWorkbook
    .SaveAs FileName:=sFileName, FileFormat:=xlText, CreateBackup:=False
  End With
End Sub

Public Sub Export_To_Txt_File()
  SaveAsTabDelimited "C:\xxxxx\yyyyy\IKB_Data_Import.txt"
  ActiveWorkbook.Close savechanges:=False
End Sub

Could someone please help me understand how can I achieve this in my macro. I tried using the range(A2:B100000).Select syntax, but it didn't work.

Being a database guy for some time, its just since last month that I have started trying my hands out in writing Excel macros - so please pardon me if this is sounds like a thread not worth this forum.

Thanks a lot.
Sanders.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Welcome to the Board!

I think the easiest way to do it is to copy just the range that you want to a new sheet, and save that sheet as a CSV. I use this method a lot.
 
Upvote 0

Forum statistics

Threads
1,215,403
Messages
6,124,710
Members
449,182
Latest member
mrlanc20

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top