View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Kevin R Kevin R is offline
external usenet poster
 
Posts: 27
Default txt file from filtered data

I guess I don't need to filter it the way I was thinking as long as I can
extract the rows that meet my criteria (status, date, employee). Then I only
need to pull from each of those rows specific cells for the txt file.

"K Dales" wrote:

Do you need to actually filter the sheet (and leave it filtered) or is the
filtering just to find the data to extract? You don't really need to filter
since you can have your code check the conditions you need. Without knowing
more, I can only outline a procedu

Sub ExtractData()

Dim DataRange as Range, ThisRow as Integer, OutputStr as String

Open "C:\EXAMPLE\Mytextfile.txt" For Append as #1 ' or, For Output

Set DataRange=Sheets("DataSheetName").Range("DataRange ")
For ThisRow = 1 to DataRange.Rows.Count
' Now read the data, line by line, using the Offset method to find the cell
you want to check, e.g:
If DataRange.Offset(ThisRow-1,2) = ??? _ ' This checks the 3rd column in
your list
Then OutputStr=DataRange.Offset(ThisRow-1,3).Range("A1").Value & "," _
& DataRange.Offset(ThisRow-1,4).Range("A1").Value
' The above creates a comma-delimited entry based on the values in columns 4
& 5
' (Note that .Offset begins with 0 for the current row/column)

Write #1, OutputStr
Next ThisRow

Close #1
End Sub

"Kevin R" wrote:

I have a worksheet that has 6 columns. The number of rows can vary. I need
to filter the worksheet on 3 of the columns to narrow the data down to what I
need to extract. Then I need to create a text file using the filtered data
so that cells A1, B1, & C1 are on a line and then D1, E1, & F1 are on the
next line. I need to repeat this in the text file for each row in the
filtered worksheet. Is this possible?