Only process filtered items

Sebas123

New Member
Joined
Aug 12, 2011
Messages
4
Hello again,

How can you let vba process "only" the filtered data (on my filtered excel sheet). The code executes and it stil executes it on all the data.


Here is an example of my code. In the sheet of this document are filtered columns. Even with filter-on, vb still processes the whole document.

Code:
Sub ExportTXT()
 
Dim rownum, colnum As Integer
Dim filename, Filelocation As String
Dim ws As Worksheet
 
Set ws = Worksheets("Sheet")
Filelocation = "C:\"
 
 With ws
        rownum = 3
        While .Cells(rownum, 1) <> ""
            filename = .Cells(rownum, 1).Value
            Open (Filelocation & filename & ".txt") For Output As #1
 
            colnum = 2
            While .Cells(rownum, colnum) <> 0
                 Print #1, ws.Cells(rownum, colnum) & vbNewLine;
                colnum = colnum + 1
            Wend
 
            Close #1
            rownum = rownum + 1
        Wend
 
    End With
 
End Sub

Can someone help me?

Thanks,
Sebas123
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Sebas123,

Give the following a try:
Code:
Sub ExportTXT()
    
    Const fPath As String = "C:\"
    Static rng As Range: Set rng = Intersect(ActiveSheet.UsedRange, Range("A3", Cells(Rows.Count, "A")))
    
    Dim rCell As Range
    Dim colnum As Long
    
    On Error GoTo NoneVisible
    For Each rCell In rng.SpecialCells(xlCellTypeVisible)
        Open fPath & rCell.Value & ".txt" For Output As #1
        colnum = 2
        While Cells(rCell.Row, colnum) <> 0
            Print #1, Cells(rCell.Row, colnum) & vbNewLine;
            colnum = colnum + 1
        Wend
        Close #1
    Next rCell
    Exit Sub
    
NoneVisible:
    MsgBox "No visible cells found"
    Exit Sub
    
End Sub



Hope that helps,
~tigeravatar
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,147
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top