Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Export (VBA) an Excel 2003 List (Filtered) to a txt/csv/xls


Hello Everybody,

I'm hoping somebody has the solution for this I already browsed through
most of the internet without any luck.

ok so let's say I have an excel spreadsheet:
A1: label1 B1: label2
A2: value1 B2: 1
A3: value2 B3: 1
A4: value3 B4: 3
A5: value4 B5: 1
A6: value5 B6: 3
A7: value6 B7: 1
A8: value7 B8: 3

I select (A1:B8) and click on create list
now I click on the drop down button of label2 and select 3 this shows
only the rows for which label2 value is 3 (basic filtering)

it would show:

A1: label1 B1: label2
A4: value3 B4: 3
A6: value5 B6: 3
A8: value7 B8: 3

OK. now I need to be able to export the filtered sheet either to a text
file, csv file, an excel file, another sheet, with a button.
the usual methods of exporting won't work because they use a for to go
through each row and this would export also the hidden rows.

going into edit-GoTo-Special-Visible Cells Only and then manually
selecting the cells and copying and pasting into another sheet is not
an answer since the spreadsheet will dynamically grow that's why I need
a VBA code that exports the current view of the sheet.

I would really appreciate any suggestions

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Export (VBA) an Excel 2003 List (Filtered) to a txt/csv/xls

You could have a macro do the work for you.

Option Explicit
Sub testme()

Dim CurWks As Worksheet
Dim NewWks As Worksheet

Set CurWks = ActiveSheet
Set NewWks = Workbooks.Add(1).Worksheets(1)

CurWks.AutoFilter.Range.Copy _
Destination:=NewWks.Range("a1")

With NewWks.Parent
.SaveAs Filename:="C:\myfile.csv", FileFormat:=xlCSV
.Close savechanges:=False
End With

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

wrote:

Hello Everybody,

I'm hoping somebody has the solution for this I already browsed through
most of the internet without any luck.

ok so let's say I have an excel spreadsheet:
A1: label1 B1: label2
A2: value1 B2: 1
A3: value2 B3: 1
A4: value3 B4: 3
A5: value4 B5: 1
A6: value5 B6: 3
A7: value6 B7: 1
A8: value7 B8: 3

I select (A1:B8) and click on create list
now I click on the drop down button of label2 and select 3 this shows
only the rows for which label2 value is 3 (basic filtering)

it would show:

A1: label1 B1: label2
A4: value3 B4: 3
A6: value5 B6: 3
A8: value7 B8: 3

OK. now I need to be able to export the filtered sheet either to a text
file, csv file, an excel file, another sheet, with a button.
the usual methods of exporting won't work because they use a for to go
through each row and this would export also the hidden rows.

going into edit-GoTo-Special-Visible Cells Only and then manually
selecting the cells and copying and pasting into another sheet is not
an answer since the spreadsheet will dynamically grow that's why I need
a VBA code that exports the current view of the sheet.

I would really appreciate any suggestions


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Export (VBA) an Excel 2003 List (Filtered) to a txt/csv/xls


Dave Peterson Wrote:
If you're new to macros, you may want to read David McRitchie's intro
at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Stumbled on this thread by chance. I'm not completely new to macros,
but there's much for me to learn from that website. Thanks a lot.


--
Lava
------------------------------------------------------------------------
Lava's Profile: http://www.excelforum.com/member.php...o&userid=27793
View this thread: http://www.excelforum.com/showthread...hreadid=479975

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Export (VBA) an Excel 2003 List (Filtered) to a txt/csv/xls

Thanks Dave I really appreciate your help.

I wanted to give the user a little bit more control so this is how it
ended thanks to your suggestions and the ones from BrianB from
Luton,England from MrExcel Message Boards.
http://www.mrexcel.com/board2/viewto...=848773#848773

Private Sub CommandButton1_Click()
On Error Resume Next
Application.DisplayAlerts = False
Sheets("filtered").Delete
Application.DisplayAlerts = True
Dim wb As Workbook ' this
Dim ws As Worksheet ' this
Dim MyRange As Range
Dim LastRow As Long
Dim FileName As String ' for text file
Dim MyRow As Long
Dim MyCol As Integer
Dim ColumnCount As Integer ' number of columns
'---------------------------------------------------------------
'- initialize variables
Set wb = ThisWorkbook
Set ws = ActiveSheet
LastRow = ws.Range("A65536").End(xlUp).Row
ColumnCount = 2
'----------------------------------------------------------------
'- Copy visible cells
Set MyRange = ws.Range(Cells(1, "A"), _
Cells(LastRow,
ColumnCount)).SpecialCells(xlCellTypeVisible)
MyRange.Copy

'================================================= ==================
'- paste to workbook (containing macro).Could use 'ActiveWorkBook'
?
Sheets.Add Type:=xlWorksheet
ActiveSheet.Name = "filtered"
wb.Worksheets("filtered").Paste _
Destination:=wb.Worksheets("filtered").Range("A1")

'================================================= ==================
'- to a comma delimited text file
FileName = Application.GetSaveAsFilename("C:\", "(*.csv), *.csv", ,
"")
If FileName < False Then
Open FileName For Output As #1
For MyRow = 1 To LastRow ' - 1
If ws.Rows(MyRow).EntireRow.Hidden = False Then
For MyCol = 1 To ColumnCount
If ((MyRange.Cells(MyRow, MyCol).Value = "") And
(MyRange.Cells(MyRow, MyCol + 1).Value = "")) Then
MyCol = ColumnCount
Else
Print #1, MyRange.Cells(MyRow, MyCol).Value;
If MyCol < ColumnCount Then Print #1, ",";
End If
Next
Print #1, ' end of line
End If
Next

'-------------------------------------------------------------------
Close #1

'================================================= ==================
MsgBox ("Done")
End If
End Sub

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 2003 + export of data Neil Holden Excel Discussion (Misc queries) 7 February 26th 10 12:53 PM
Excel 2003 - define name like a filtered list Hershmab Excel Discussion (Misc queries) 1 October 30th 09 02:07 PM
SAP export to Excel 2003 Lance Hebert[_2_] Excel Discussion (Misc queries) 1 January 28th 09 11:16 PM
how do I select different data in a filtered column in excel 2003? Manisha Excel Discussion (Misc queries) 1 May 2nd 08 01:55 PM
How can I export an excel 2003 chart to a .jpg? Jason Krause Charts and Charting in Excel 3 August 18th 05 10:39 PM


All times are GMT +1. The time now is 04:59 PM.

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"