looping in vba for excel
Sorry, my mistake. Try this instead
Dim iLastRow As Long
Dim iLastCol As Long
Dim i As Long, j As Long
Open "TESTFILE" For Output As #1
iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
If Cells(i, "A").Value = "x" Then
ary = Rows(i)
For j = 1 To Cells(i, Columns.Count).End(xlToLeft).Column - 1
Print #1, Cells(i, j),
Next j
Print #1, Cells(i, j)
End If
Next i
Close #1
--
HTH
Bob Phillips
"Access101" wrote in message
...
This line causes this error -- Run Time Err 13: Type Mismatch
Print #1, Rows(i).EntireRow
"Bob Phillips" wrote:
Dim iLastRow As Long
Dim i As Long
Open "TESTFILE" For Output As #1
iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
If Cells(i, "A").Value = "x" Then
Print #1, Rows(i).EntireRow
End If
Next i
Close #1
as an example
--
HTH
Bob Phillips
wrote in message
oups.com...
What I'm looking to do is write to a
file the specific rows I sorted on. One record per line.
I know, it sounds re-dundant, but it's part of a larger picture.
fyi. the column value for the records I need write is x. if there's
an x in that comlumn for a record, write the record to a text file.
Now, since it's been over a decade since I last coded, I can't figure
out to start with what kind of loop to do. For, while, etc. And how I
read from the Excel spreadsheet.
Thanks in advance.
-Michael
Psuedo code:
For each row with column "T"="x" Do
Write row to c:\sorted_data.txt
End For
|