PC Review


Reply
Thread Tools Rate Thread

Copy selected columns from .xls to a .txt file question

 
 
gedinfo
Guest
Posts: n/a
 
      3rd Dec 2009
I would like to be able to copy two columns from a .xls file, columns 2
(B) and 9(I) into a .txt file for approximately 100 rows, using VBA.
What is the best way to do this?

Thank you
 
Reply With Quote
 
 
 
 
muddan madhu
Guest
Posts: n/a
 
      3rd Dec 2009
try this

Sub Copy_Rows()

With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With

FpatH = "C:\Documents and Settings\username\filename.xls"

Workbooks.Open FpatH
FileP = ActiveWorkbook.path
Range("B1:C100").Copy
Workbooks.Add
ActiveSheet.Paste

ActiveWorkbook.SaveAs Filename:= _
FileP & "\" & "1.txt", FileFormat:=xlUnicodeText,
CreateBackup:=False

ActiveWorkbook.Close True

With Application
.DisplayAlerts = True
.ScreenUpdating = True
.CutCopyMode = False
End With

End Sub




On Dec 3, 10:00*am, gedinfo <sche...@gmail.com> wrote:
> I would like to be able to copy two columns from a .xls file, columns 2
> (B) and 9(I) into a .txt file for approximately 100 rows, using VBA.
> What is the best way to do this?
>
> Thank you


 
Reply With Quote
 
Phuelgod
Guest
Posts: n/a
 
      3rd Dec 2009
Couple questions:

- Does the .txt file already exist, or are you wanting to create a new .txt
file with just the table in it?

- Do you want two 1x100 tables or one 2x100 table?

--
Frank

"Do or do not; There is no try"
-Yoda


"gedinfo" wrote:

> I would like to be able to copy two columns from a .xls file, columns 2
> (B) and 9(I) into a .txt file for approximately 100 rows, using VBA.
> What is the best way to do this?
>
> Thank you
> .
>

 
Reply With Quote
 
gedinfo
Guest
Posts: n/a
 
      3rd Dec 2009
On Dec 2, 11:45*pm, Phuelgod <frank(removethis)case...@comcast.net>
wrote:
> Couple questions:
>
> - Does the .txt file already exist, or are you wanting to create a new .txt
> file with just the table in it?
>
> - Do you want two 1x100 tables or one 2x100 table?
>
> --
> Frank
>
> "Do or do not; There is no try"
> * *-Yoda
>
>
>
> "gedinfo" wrote:
> > I would like to be able to copy two columns from a .xls file, columns 2
> > (B) and 9(I) into a .txt file for approximately 100 rows, using VBA.
> > What is the best way to do this?

>
> > Thank you
> > .- Hide quoted text -

>
> - Show quoted text -


Hello Frank,

It does not matter whether or not the file exists; I have test code to
either open or create.

As for the other question, I am only looking for two entries of 100,
so 2 single tables.

Thank you
 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      3rd Dec 2009
> As for the other question, I am only looking for two entries
> of 100, so 2 single tables.


This will place the first 100 cells (line feed delimited) in Column B in the
indicated variable...

Col_B = Join(WorksheetFunction.Transpose(Range("B1:B100")), vbLf)

and this will do the same for Column I...

Col_I = Join(WorksheetFunction.Transpose(Range("I1:I100")), vbLf)

You can replace the 100 in each statement with a calculated value for the
Last Row if you will not have exactly 100 entries and you only want the
values for the number of cells down to the last filled in row in that
column. For example, for the Col_B variable (do similarly for the Col_I
variable)...

LastRow = Cells(Rows.Count, "B").End(xlUp).Row
Col_B = Join(WorksheetFunction.Transpose(Range("B1:B" & LastRow)), vbLf)

You can process these variables out to your file in whatever order you want.

--
Rick (MVP - Excel)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy some of selected columns to master sheet sanju Microsoft Excel Programming 1 14th Apr 2010 04:49 AM
Copy and paste selected columns between Excel workbooks Orimslala Microsoft Excel Programming 4 4th Apr 2008 10:21 AM
print selected columns in query OMIT LAST QUESTION =?Utf-8?B?Umljaw==?= Microsoft Access Queries 1 13th Sep 2007 07:58 PM
How I can copy / paste a selected cells to other columns in Excel =?Utf-8?B?TS5SYWZhdA==?= Microsoft Excel Misc 4 7th Nov 2006 05:42 AM
Copy selected columns only Mac Microsoft Excel Programming 2 18th Dec 2003 01:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:49 PM.