+ Reply to Thread
Results 1 to 16 of 16

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

Hybrid View

  1. #1
    Registered User
    Join Date
    02-22-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

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

    Hi

    i have a multiple records (30 k) in a excel workbook , in that i want take only 3 records of email per company,

    ex: the company having 10 email in that only three email i need to copy or remove and keep in separate excel workbook.

    if the company having less then three, the same count or email i need to copy or remove and keep in separate excel workbook.

    i have kept the same file also.

    please help me how to do.

    thanks and regards
    Josh
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    02-22-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

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

    any one can help me......

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,687

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

    You have not received any responses because your explanation is not clear. Please provide a sample of the what the solution should look like. (prepared manually) No one knows what your logic is to achieve your expected solution. Help us to help you with more information and examples of the solution.

    Alan
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    02-22-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

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

    Quote Originally Posted by alansidman View Post
    You have not received any responses because your explanation is not clear. Please provide a sample of the what the solution should look like. (prepared manually) No one knows what your logic is to achieve your expected solution. Help us to help you with more information and examples of the solution.

    Alan

    please find the attached file, which is colored in yellow records as to copy and past in another sheet.(<=3 records copy to another sheet)

    please help me

    regards
    Josh
    Attached Files Attached Files

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

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

    Hi perusjosh

    Here's a VBA solution
    Option Explicit
    
    Sub Get_Three()
        Dim ws As Worksheet, ws1 As Worksheet
        Dim LR As Long, LR1 As Long, x As Long
        Dim Rng As Range, cel As Range
    
        Set ws = Sheets("original file") '<----Change Sheet Name as required
        Set ws1 = Sheets("OutPut")       '<----Change Sheet Name as required
    
        Application.ScreenUpdating = False
        With ws1
            .UsedRange.Offset(1, 0).Clear
        End With
    
        If Not Evaluate("ISREF(Lists!A1)") Then
            Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Lists"
            ActiveSheet.Range("A1").Value = "Webaddress"
            ActiveSheet.Range("B1").Value = "Email Address"
        Else
            Sheets("Lists").UsedRange.Offset(1, 0).ClearContents
        End If
        With ws
            LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                    SearchDirection:=xlPrevious).Row
    
            .Range("A1:A" & LR).Copy
            With Sheets("Lists")
                .Range("A1").PasteSpecial (xlPasteValues)
                .Range(("A1"), .Range("A1").End(xlDown)).RemoveDuplicates Columns:=1, Header:=xlYes
                ActiveWorkbook.Names.Add Name:="Webaddress", RefersTo:= _
                        "=OFFSET(Lists!$A$2,0,0,(COUNTA(Lists!$A:$A)-1),1)"
            End With
            If Not .AutoFilterMode Then
                .Range("A1").AutoFilter
            End If
            With .Range("A1:A" & LR)
                For Each cel In Range("Webaddress")
                    .AutoFilter Field:=1, Criteria1:=cel.Value
    
                    Set Rng = ws.AutoFilter.Range
                    x = Rng.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1
                    If x <= 3 Then
                        With ws1
                            LR1 = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                                    SearchDirection:=xlPrevious).Row + 1
                        End With
                        .Range("A2:B" & LR).SpecialCells(xlCellTypeVisible).Copy
                        ws1.Range("A" & LR1).PasteSpecial (xlPasteValues)
                        ws1.Range("C" & LR1).Resize(x, 1).Value = x
                    Else
                        With ws1
                            LR1 = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                                    SearchDirection:=xlPrevious).Row + 1
                        End With
                        .Range("A2:B" & LR).SpecialCells(xlCellTypeVisible).Copy
                        ws1.Range("A" & LR1).PasteSpecial (xlPasteValues)
                        ws1.Range("C" & LR1).Resize(x, 1).Value = 3
                        ws1.Range("A" & LR1 + 3).Resize(x, 1).EntireRow.Delete
                    End If
                Next cel
            End With
            .ShowAllData
        End With
        ws1.Activate
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  6. #6
    Registered User
    Join Date
    02-22-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

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

    Hi thanks a lot
    excellent solution you have given to me.

    Small changes required in this.
    if criteria is changing to instead of 3 , if i want 5 records how to get it.
    So, please give me the option that at button 1(how many records you want __ ) if i enter the cont
    according to that it will separate the records.

    thanks a lot for your wonderful solution once again.

    josh

  7. #7
    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,042

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

    Use another helper column, D

    Cell D4:
    Formula: copy to clipboard
    =COUNTIF($A$2:$A2,$A2) 
    and drag down.

    Filter column D on less than or equal to 3. Copy visible records to the new sheet.

    Regards, TMS


    Edit: error in formula ... change $A$2,$A2,$A2 to $A$2:$A2,$A2
    Last edited by TMS; 09-21-2013 at 02:02 PM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  8. #8
    Banned User!
    Join Date
    10-14-2006
    Posts
    1,211

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

    See the attached file
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    02-22-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

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

    Hi mama ,
    Thanks a lot, i'm not able to use more records, i have 5000 records, so how extend the formula(i'm not able to copy and past the formula- when am doing the following error show's - *you cannot change part of an array*)

    once again thanks a lot.

    josh

  10. #10
    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,042

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

    Another VBA solution:

    Option Explicit
    
    Sub sCopyEMailAddresses()
    
    Dim lLR As Long
    
    Application.ScreenUpdating = False
    
    ' using sheet1 ...
    With Sheet1
        ' 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("C2:C" & lLR).Formula = _
            "=COUNTIF($A$2:$A2,$A2)"
        ' filter the records
        With .Range("$A$1:$C$" & lLR)
            .AutoFilter
            .AutoFilter _
                Field:=3, _
                Criteria1:="<=3"
        End With
    End With
    
    ' prepare sheet2 ...
    With Sheet2
        ' clear existng data
        .Cells.Delete
    End With
    
    ' back on sheet1 ...
    With Sheet1
        ' copy visble cells in columns A and B to sheet2
        With .Range("$A$1:$B$" & lLR)
            .SpecialCells(xlCellTypeVisible).Copy _
                Sheet2.Range("A1")
            ' switch off the filter
            .AutoFilter
            ' remove the helper column
            .Range("C1").EntireColumn.Delete
        End With
    End With
    
    ' and back on sheet2 ...
    With Sheet2
        ' make the columsn the right width
        .Range("A1:B1").EntireColumn.AutoFit
    End With
    
    Application.ScreenUpdating = True
    
    End Sub

    Regards, TMS

  11. #11
    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,042

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

    Ah ... scope creep. In reality, you have had several solutions to your original question and, as such, this thread should now be marked solved.

    I am assuming that you are only going to want to vary the number of records extracted occasionally so, rather than add the overhead of front end code which will rarely be used, you might just as well edit the filter.

    For example, in my code, you would change:

                Criteria1:="<=3"

    to:

                Criteria1:="<=5"

    You should also bear in mind that my code simply automates the manual solution offered in post #5.


    If you really need the additional code, I would suggest you ask for it in a separate thread.


    Regards, TMS


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  12. #12
    Registered User
    Join Date
    02-22-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

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

    Hi,

    i have 1000 records, how can i make it,

    u have given the solution but, its work only one criteria but criteria may change.

    please help me solve.

    josh.

  13. #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,042

    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 ...

  14. #14
    Registered User
    Join Date
    02-22-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

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

    hi,
    am try to do with your code but am getting the error.

    please how to execute the code or

    i'm attaching the file kindly insert the code and send to me.

    information required: can is use any number of records in this code.


    regards
    Josh
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    02-22-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

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

    Hi TMS,

    Please help me to do this

    regards
    Josh

  16. #16
    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,042

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

    Thought I'd already done this ...

    Suspect the forum problems prevented the upload.

    See attached example

    Regards, TMS
    Attached Files Attached Files

+ 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. 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