+ Reply to Thread
Results 1 to 4 of 4

Copy paste first and last row based on two criteria to a new sheet

  1. #1
    Registered User
    Join Date
    05-23-2019
    Location
    Luxembourg
    MS-Off Ver
    2018
    Posts
    6

    Copy paste first and last row based on two criteria to a new sheet

    Hello Team,

    I am trying to get the first and last row with a VBA code where it filter the list based on a code and currency, then i would like the VBA code to copy the first row and last of filtered data.

    The issue am getting with the below code is that it copies the header when there are no transaction but a code has been referenced in the account number sheet. The account number sheet is a kind of a permanent list of bank account number and currency and every month we have transaction and some accounts may not have also.

    Can you also please help add the first row code as I could not figure it out.

    Thank you

    Sub FilterData()
    Application.ScreenUpdating = False
    Dim LastRow As Long, acSheet As Worksheet, srcWS As Worksheet, desWS As Worksheet, code As Range
    Set acSheet = Sheets("Account Number")
    Set srcWS = Sheets("Summary")
    Set desWS = Sheets("Ending Balance")
    LastRow = acSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For Each code In acSheet.Range("A4:A" & LastRow)
    With srcWS.Cells(1).CurrentRegion
    .AutoFilter 1, code
    .AutoFilter 2, code.Offset(, 1)
    srcWS.Range("A" & Rows.Count).End(xlUp).EntireRow.Copy desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1)
    End With
    Next code
    srcWS.Range("A1").AutoFilter
    Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,777

    Re: Copy paste first and last row based on two criteria to a new sheet

    Try:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    05-23-2019
    Location
    Luxembourg
    MS-Off Ver
    2018
    Posts
    6

    Re: Copy paste first and last row based on two criteria to a new sheet

    Thank you very much Mumps1

    It work perfectly.

    Thank you once again

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,777

    Re: Copy paste first and last row based on two criteria to a new sheet

    You are very welcome.

+ 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. VBA to copy to new sheet and paste to last empty row based on criteria
    By Makroz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-19-2019, 10:32 AM
  2. Copy & Paste from an Excel Sheet to Another sheet Based on Certain Criteria
    By SPAARK in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-04-2019, 10:14 PM
  3. [SOLVED] VBA to Copy & paste values from one sheet to another based on criteria.
    By rossi_69 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-05-2018, 08:04 AM
  4. [SOLVED] Copy and paste columns to another sheet based on a criteria
    By saya_26 in forum Excel General
    Replies: 17
    Last Post: 02-24-2014, 12:23 PM
  5. [SOLVED] Copy/Paste a column in a new sheet based on a criteria
    By Elorac in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-19-2013, 02:01 PM
  6. Copy and Paste Rows based on Criteria onto another sheet and sort based on oldest item
    By Kushal8684 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2013, 05:37 AM
  7. [SOLVED] Copy and paste data from sheet 2 to sheet 1 based on specific criteria on sheet 1
    By VBADUD in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2012, 04:18 AM

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