Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Copy List Columns

I have a table in excel I would like to copy, the table has many records in
it. I have code that will filter the data to show only a few records. I need
to copy just the visible data from 3 consecutive columns and paste into
another workbook. Is there a way to copy all 3 columns at once?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Copy List Columns

After filtering, you can use SpecialCells to select only visible cells, then
copy & paste into the other workbook. This example creates a second workbook,
applies an autofilter in the the first workbook, selects only visible cells
in columns C-E, then copies & pastes those columns into the second workbook:

Sub Macro1()
Dim NewWB As Workbook, StartWB As Workbook
Set StartWB = ActiveWorkbook
Workbooks.Add
Set NewWB = ActiveWorkbook
StartWB.Activate
Sheets("Sheet1").Select

'Apply the filter here
Range("C1").Select
Selection.CurrentRegion.Select
Selection.AutoFilter Field:=1, Criteria1:="x"

Columns("C:E").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
NewWB.Activate
Sheets("Sheet1").Select
Range("C1").Select
ActiveSheet.Paste
'Free object variables when done
Set StartWB = Nothing
Set NewWB = Nothing
End Sub

Hope this helps,

Hutch

"Brad" wrote:

I have a table in excel I would like to copy, the table has many records in
it. I have code that will filter the data to show only a few records. I need
to copy just the visible data from 3 consecutive columns and paste into
another workbook. Is there a way to copy all 3 columns at once?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Copy List Columns

is there a way to do this without selecting the columns?

The reason I ask is because, this code is executing inside of a loop that
is heavily reliant on ActiveCell.offset(x , 1).

"Tom Hutchins" wrote:

After filtering, you can use SpecialCells to select only visible cells, then
copy & paste into the other workbook. This example creates a second workbook,
applies an autofilter in the the first workbook, selects only visible cells
in columns C-E, then copies & pastes those columns into the second workbook:

Sub Macro1()
Dim NewWB As Workbook, StartWB As Workbook
Set StartWB = ActiveWorkbook
Workbooks.Add
Set NewWB = ActiveWorkbook
StartWB.Activate
Sheets("Sheet1").Select

'Apply the filter here
Range("C1").Select
Selection.CurrentRegion.Select
Selection.AutoFilter Field:=1, Criteria1:="x"

Columns("C:E").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
NewWB.Activate
Sheets("Sheet1").Select
Range("C1").Select
ActiveSheet.Paste
'Free object variables when done
Set StartWB = Nothing
Set NewWB = Nothing
End Sub

Hope this helps,

Hutch

"Brad" wrote:

I have a table in excel I would like to copy, the table has many records in
it. I have code that will filter the data to show only a few records. I need
to copy just the visible data from 3 consecutive columns and paste into
another workbook. Is there a way to copy all 3 columns at once?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Copy List Columns

Here is an example

Sub Macro1()
Dim r As Range
Set r = Range("A1")
Application.ScreenUpdating = False
r.AutoFilter
r.AutoFilter Field:=1, Criteria1:="Apples"
r.SpecialCells(xlCellTypeVisible).Copy _
Destination:=Worksheets("Sheet2").Range("A1")
r.AutoFilter
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
How do I copy columns between worksheets if the columns don't matc Miriam Excel Worksheet Functions 10 June 12th 06 04:29 PM
Copy columns values into separate columns Mike_can Excel Discussion (Misc queries) 7 May 27th 06 12:32 AM
Copy # fm one list to matching id in list 2? Curalice Excel Worksheet Functions 3 February 10th 06 09:33 PM
Copy a row from one sheet to another and not all columns copy Peaches[_2_] Excel Programming 2 September 7th 05 12:09 PM
How to remove duplicates from a list and copy new list to new colu Chance Excel Worksheet Functions 2 April 23rd 05 05:21 AM


All times are GMT +1. The time now is 12:41 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"