[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 481
  • Last Modified:

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

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
robjay
Asked:
robjay
  • 2
1 Solution
 
tureCommented:
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
 
tureCommented:
Just a friendly reminder...
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now