Results 1 to 16 of 16

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

Threaded View

perusjosh copy or remove particular... 09-19-2013, 03:06 AM
perusjosh Re: copy or remove ... 09-20-2013, 09:32 AM
alansidman Re: copy or remove ... 09-20-2013, 09:48 AM
perusjosh Re: copy or remove ... 09-21-2013, 02:32 AM
jaslake Re: copy or remove ... 09-21-2013, 11:34 AM
perusjosh Re: copy or remove ... 09-24-2013, 12:29 AM
TMS Re: copy or remove ... 09-21-2013, 09:28 AM
Teethless mama Re: copy or remove ... 09-21-2013, 09:59 AM
perusjosh Re: copy or remove ... 09-24-2013, 04:59 AM
TMS Re: copy or remove ... 09-21-2013, 03:06 PM
TMS Re: copy or remove ... 09-24-2013, 05:34 AM
perusjosh Re: copy or remove ... 09-24-2013, 06:39 AM
TMS Re: copy or remove ... 09-24-2013, 08:17 AM
perusjosh Re: copy or remove ... 09-25-2013, 12:43 AM
perusjosh Re: copy or remove ... 09-26-2013, 09:43 AM
TMS Re: copy or remove ... 09-26-2013, 09:55 AM
  1. #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.

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