Results 1 to 16 of 16

copy or remove particular count of records and pasting in another excel workbook

Threaded View

  1. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,082

    Re: copy or remove particular count of records and pasting in another excel workbook

    OK, maybe this:

    Option Explicit
    
    Sub sCopyEMailAddresses()
    
    Dim lLR As Long
    Dim sHowMany As String
    Dim lHowMany As Long
    
    sHowMany = InputBox("Please enter the maximum number of EMail addresses to be copied", _
                        "Maximum EMail Addresses", _
                        3)
    
    If Trim(sHowMany) = "" Or sHowMany = "0" Then Exit Sub
    
    lHowMany = sHowMany
    
    Application.ScreenUpdating = False
    
    ' using sheet1 ...
    With Sheet1     ' original file
        ' determine how many rows of data (based on column A)
        lLR = .Range("A" & .Rows.Count).End(xlUp).Row
        ' add helper formula in column C
        .Range("D2:D" & lLR).Formula = _
            "=COUNTIF($A$2:$A2,$A2)"
        ' filter the records
        With .Range("$A$1:$D$" & lLR)
            .AutoFilter
            .AutoFilter _
                Field:=4, _
                Criteria1:="<=" & lHowMany
        End With
    End With
    
    ' prepare sheet2 ...
    With Sheet2     ' required records
        ' clear existing data
        .Cells.Delete
    End With
    
    ' back on sheet1 ...
    With Sheet1     ' original file
        ' copy visble cells in columns A and B to sheet2
        With .Range("$A$1:$C$" & lLR)
            .SpecialCells(xlCellTypeVisible).Copy _
                Sheet2.Range("A1")
            ' switch off the filter
            .AutoFilter
            ' remove the helper column
            .Range("D1").EntireColumn.Delete
        End With
    End With
    
    ' and back on sheet2 ...
    With Sheet2     ' required records
        ' make the columns the right width
        .Range("A1:C1").EntireColumn.AutoFit
    End With
    
    Application.ScreenUpdating = True
    
    End Sub

    Regards, TMS
    Last edited by TMS; 09-24-2013 at 08:25 AM. Reason: fix teeny tiny typo ...

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 7
    Last Post: 07-05-2013, 01:23 PM
  2. [SOLVED] Problem pasting data into new workbook when worksheet has no records
    By sokker23 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-16-2013, 05:35 PM
  3. Replies: 0
    Last Post: 08-11-2011, 01:23 AM
  4. Copy Pasting data from one excel workbook to another using vba
    By wahaj in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-10-2009, 02:50 AM
  5. Copy records with the same value in a column to a new sheet or workbook
    By reeyasen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-30-2008, 11:29 PM

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