+ Reply to Thread
Results 1 to 2 of 2

macro to auto filter and then paste certain columns to another sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    10-14-2011
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    8

    macro to auto filter and then paste certain columns to another sheet

    Hi there.

    I am running a auto filter macro to i need to change it to only copy column A:B and past in column C:D in the sheet called "Diary". Can any body assist me to change my current macro to only select column A:B and paste it. It is currently pasting the entire row.

    Here is the part of my code:
     'Check if there are not more then 8192 areas(limit of areas that Excel can copy)
        CCount = 0
        On Error Resume Next
        CCount = My_Range.Columns(1).SpecialCells(xlCellTypeVisible).Areas(1).Cells.Count
        On Error GoTo 0
        If CCount = 0 Then
            MsgBox "There are more than 8192 areas:" _
                 & vbNewLine & "It is not possible to copy the visible data." _
                 & vbNewLine & "Tip: Sort your data before you use this macro.", _
                   vbOKOnly, "Copy to worksheet"
        Else
            'Copy the visible data and use PasteSpecial to paste to the Destsh
            With My_Range.Parent.AutoFilter.Range
                On Error Resume Next
                ' Set rng to the visible cells in My_Range without the header row
                
                Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count) _
                          .SpecialCells(xlCellTypeVisible)
                On Error GoTo 0
                If Not rng Is Nothing Then
                    'Copy and paste the cells into DestSh below the existing data
                    rng.Copy
                    With DestSh.Range("A" & LastRow(DestSh) + 1)
                        ' Paste:=8 will copy the columnwidth in Excel 2000 and higher
                        ' Remove this line if you use Excel 97
                       ' .PasteSpecial Paste:=8
                        .PasteSpecial xlPasteValues
                        .PasteSpecial xlPasteFormats
                        Application.CutCopyMode = False
                    End With
                    'Delete the rows in the My_Range.Parent worksheet
                    'rng.EntireRow.Delete
                End If
            End With
        End If

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: macro to auto filter and then paste certain columns to another sheet

    Change this line

     Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count) _
                          .SpecialCells(xlCellTypeVisible)
    INTO

     Set Rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
                          .SpecialCells(xlCellTypeVisible)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] I'm a new user: Need a macro that will auto paste data from one sheet row to another sheet
    By Daotor in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-22-2013, 10:15 AM
  2. auto filter macro, select columns
    By Greed in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2011, 09:59 AM
  3. Filter, copy specific columns, and paste to another sheet as VALUES ONLY
    By elobelix in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-04-2010, 11:59 AM
  4. Filter, copy specific columns, and paste to another sheet.
    By Xrull in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 09-29-2009, 06:33 AM
  5. need code for copy/paste, highlighting columns and enabling auto-filter/freeze panes
    By excelaspire0219 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-09-2009, 05:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1