localfiend
Board Regular
- Joined
- Mar 15, 2006
- Messages
- 166
After a bit of searching around on the web I was able to get some code working that creates a .txt file from cell values.
However the text file I need to create involves a whole lot of cells, and using the quick and dirty code below tends to make excel puke itself.
Can anyone show me how to simplify the "Print #iFileNum" section? It's abbvreviated for the moment and only shows code for rows 2 and 3. I need to to repeat that section of code all the way down to row 600. I can normally do something like this, but the freefile function being in there has me scratching my head.
Thanks,
However the text file I need to create involves a whole lot of cells, and using the quick and dirty code below tends to make excel puke itself.
Can anyone show me how to simplify the "Print #iFileNum" section? It's abbvreviated for the moment and only shows code for rows 2 and 3. I need to to repeat that section of code all the way down to row 600. I can normally do something like this, but the freefile function being in there has me scratching my head.
Thanks,
Code:
' Declare stuff
Dim sFile As String
Dim sLine As String
Dim iFileNum As Integer
' Text File Location
sFile = "C:\temp\test.txt"
iFileNum = FreeFile
Open sFile For Output As iFileNum
' Make the Text File
With Worksheets("httpd")
Print #iFileNum, .Range("A2").Value
Print #iFileNum, .Range("B2").Value
Print #iFileNum, .Range("C2").Value
Print #iFileNum, .Range("D2").Value
Print #iFileNum, .Range("E2").Value
Print #iFileNum, .Range("F2").Value
Print #iFileNum, .Range("G2").Value
Print #iFileNum, .Range("H2").Value
Print #iFileNum, .Range("I2").Value
Print #iFileNum, .Range("J2").Value
Print #iFileNum, .Range("K2").Value
Print #iFileNum, .Range("A3").Value
Print #iFileNum, .Range("B3").Value
Print #iFileNum, .Range("C3").Value
Print #iFileNum, .Range("D3").Value
Print #iFileNum, .Range("E3").Value
Print #iFileNum, .Range("F3").Value
Print #iFileNum, .Range("G3").Value
Print #iFileNum, .Range("H3").Value
Print #iFileNum, .Range("I3").Value
Print #iFileNum, .Range("J3").Value
Print #iFileNum, .Range("K3").Value
End With
Close #iFileNum