Solved

VB Excel: Read cell data, write it to a text file

Posted on 2000-04-05
2
476 Views
Last Modified: 2008-03-17
I need to read an excel data cell (row) and then print the data (array) to a text file.  Could someone provide a code snippet?
0
Comment
Question by:robjay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 22

Expert Comment

by:ture
ID: 2687069
robjay,

This procedure reads rows 1-3, columns 1-5 from Sheet1 and writes to c:\test\test.txt

Sub ReadAndWrite()
  Dim ws As Worksheet
  Dim r As Long
  Dim c As Long
  Dim f As Integer
 
  Set ws = Sheets("Sheet1")
 
  f = FreeFile
  Open "c:\test\test.txt" For Output As f
 
  For r = 1 To 3
    For c = 1 To 5
      Print #f, ws.Cells(r, c),
    Next c
    Print #f,
  Next r
 
  Close f
End Sub

Ture Magnusson
Karlstad, Sweden
0
 
LVL 22

Accepted Solution

by:
ture earned 100 total points
ID: 2703120
Just a friendly reminder...
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month6 days, 13 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question