LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default Copying cell values to a external file in VBA

Im looking for a piece of code which looks through cells and exports
the text in the cell into a .txt file. on each new row, column A must
contain a 2, if not the macro stops. Also after every cell copied into
the txt file, a comma needs to separate the values in the txt file.
for example this is my data:
A B C D E
F
2 5977494A Shaw Ann 1943/06/18 45 Sarto Park
2 1613589R Nolan Mary 1945/10/31 4 Priory Grove St
2 6112747J Kennedy Harry 1946/02/12 50 Raheen Road

so the txt file will look like:
2,5977494A,Shaw,Ann,1943/06/18,45 Sarto Park
2,1613589R,Nolan,Mary,1945/10/31,4 Priory Grove St
2,6112747J,Kennedy,Harry,1946/02/12,50 Raheen Road

This is the code i have already, just cant seem to crack it!

Sub Report_Body()

Dim Cell_Loc As String
Dim Cell_Num As Integer
Dim Cell_Contents As String
Dim Output As String
newfname = "C:\Documents and Settings\mcragg\My Documents\Excel
Reports\CWPS Folder\Record.txt"
Open newfname For Output As #2
Cell_Contents = 2
Cell_Num = 2

Do While Cell_Contents = "2"

Cell_Loc = "A" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","

Cell_Loc = "B" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","

Cell_Loc = "C" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","

Cell_Loc = "D" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","

Cell_Loc = "E" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","

Cell_Loc = "F" & Cell_Num
Cell_Contents = Worksheets("Sheet1").Range(Cell_Loc).Value
Output = Output & Cell_Contents
Output = Output & ","

Any help much appreciated

Matt

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving worksheet in new file with date AND cell value as file name michaelberrier Excel Discussion (Misc queries) 4 May 26th 06 08:05 PM
Help with this conditional IF statement C-Dawg Excel Discussion (Misc queries) 3 May 15th 06 06:01 PM
resetting last cell jagdish.eashwar Excel Discussion (Misc queries) 11 March 31st 06 02:06 AM
Save External Link Values Stephane Excel Discussion (Misc queries) 0 January 3rd 05 11:01 AM
Using Jet to read excel file returns blank for last cell - sometim Ron Excel Discussion (Misc queries) 1 December 9th 04 08:21 AM


All times are GMT +1. The time now is 11:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"