Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default looping in vba for excel

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default looping in vba for excel


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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default looping in vba for excel


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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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






Reply
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
Excel Macro Looping Helps Jurassien Excel Discussion (Misc queries) 9 February 10th 07 12:44 AM
Looping through Excel Applications big t Excel Programming 2 September 22nd 05 02:21 PM
Looping with Excel Forms Jeffrey R Dempsey Excel Programming 2 June 18th 05 11:26 AM
Excel VBA - Help looping through all but 2 workbooks waveracerr[_19_] Excel Programming 1 April 1st 04 01:50 PM
Excel VBA-Looping through Multiselection jpendegraft Excel Programming 1 February 3rd 04 02:27 PM


All times are GMT +1. The time now is 11:20 AM.

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"