save filtered range to text file

rkhong

New Member
Joined
Aug 28, 2018
Messages
2
There are 6 columns and I'm using autofilter to filter from 2 columns, however I want to copy and paste another column (after filtering) to a text file.





' Getting the day of the current date
var = Day(Date)

'Autofilter
ActiveSheet.Range("A:F").AutoFilter Field:=3, Criteria1:="=Daily", _
Operator:=xlOr, Criteria2:="=var"


'Get the number of rows in Report column
LastRow = ActiveSheet.UsedRange.Rows.Count

'Loop through the column and paste the report names in the txt file
For iCntr = 2 To LastRow
Write #1 , Range("F" & iCntr)

Next iCntr
Close #1


The loop pastes all the values in COLUMN F. But I want to paste only filtered values.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Welcome to the forum

Try this
(untested)

Code:
Dim[COLOR=#ff0000] rng [/COLOR]As Range,[COLOR=#ff0000] cel [/COLOR]As Range

Var = Day(Date)

[I]'Autofilter[/I]
ActiveSheet.Range("A:F").AutoFilter Field:=3, Criteria1:="=Daily", _
Operator:=xlOr, Criteria2:="=var"

[I]'Get the number of rows in Report column[/I]
lastrow = ActiveSheet.UsedRange.Rows.Count

[COLOR=#ff0000][I]'consider visible rows only[/I]
[/COLOR]Set [COLOR=#ff0000]rng[/COLOR] = ActiveSheet.Range("F2:F" & lastrow)[COLOR=#ff0000].SpecialCells(xlCellTypeVisible)[/COLOR]

[I]'Loop through the column and paste the report names in the txt file[/I]
For Each [COLOR=#ff0000]cel [/COLOR]In [COLOR=#ff0000]rng
   [/COLOR] Write [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1"]#1[/URL] [COLOR=#ff0000], cel.Value
[/COLOR]Next[COLOR=#ff0000] cel[/COLOR]
Close [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1"]#1[/URL]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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