Results 1 to 18 of 18

Copy and Specific Paste based on Criteria

Threaded View

  1. #1
    Forum Contributor
    Join Date
    09-02-2013
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    368

    Copy and Specific Paste based on Criteria

    Hello everyone and happy Friday,

    I would like to be able to run a report from a data sales which could be very long as it records all sales data from different fruits every month and every financial year.

    The thing is not every fruit has a report for the month so sometimes, there is a gap or also the report comes in later so the chronological order is not always respected on the Sales data (as highlighted in the workbook).

    Pivot can give me part of what I want but not what I really want, which is to see whether the status report of every fruit on a monthly basis (as per the Report worksheet).

    I put on the Report sheet some more explanation but really what I want to achieve is that a monthly overview of sales for a selected fruit for a selected FY(financial year) and that overview always follow the start of the FY which is May and ends in April. So if there is no report then it will be a gap on the corresponding month, and if there is a value then that will be copied on the corresponding month as well. . If there is only one report, let's say only Sep-18 for one type of fruit for the whole year, then that would be displayed on the result on the 9th row of the result and not at the top of the row as it searches for the empty one.

    What I thought:
    - Either do vba custom sort on the range E8:G19 but I think it will be tricky
    - Or add a integer j for the column but then as the FY changes, I wasn't sure how it will work.

    I'm sure there is a better way for achieving this from the existing code.

    Sub Report()
    
    Dim i As Integer
    Dim finalRow As Integer
    Dim lngR As Long
    
    Dim wksA As Worksheet
    Dim wksB As Worksheet
    
    Set wksB = Worksheets("Report")
    Set wksA = Worksheets("Sales")
    
    wksB.Range("E8:G19").ClearContents
    
    
    finalRow = wksA.Range("B10000").End(xlUp).Row
    
        If wksB.Range("C4").Value = "" Then
        MsgBox ("Nothing to Search. Check Fields to Complete.")
        Exit Sub
        End If
    
    For i = 2 To finalRow
          If wksB.Range("C4").Value <> 0 And wksA.Cells(i, 2).Value = wksB.Range("C4").Value And wksA.Cells(i, 3) = wksB.Range("C6").Value Then
              
               lngR = Application.Max(wksB.Range("E40").End(xlUp).Row, _
               wksB.Range("F40").End(xlUp).Row, _
               wksB.Range("G40").End(xlUp).Row) + 1
                  
            wksA.Cells(i, 5).Copy
            wksB.Range("E" & lngR).PasteSpecial Paste:=xlPasteValues
            
            wksA.Cells(i, 7).Copy
            wksB.Range("F" & lngR).PasteSpecial Paste:=xlPasteValues
            
            wksA.Cells(i, 8).Copy
            wksB.Range("G" & lngR).PasteSpecial Paste:=xlPasteValues
            
          End If
        Next i
        
    wksB.Range("C4").Select
    
    End Sub
    I really appreciate your help and thank you very much.

    Rako
    Attached Files Attached Files
    Last edited by rakotonirinas; 05-10-2019 at 08:09 AM. Reason: More Info

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA Macro: Copy and Paste Specific Row Range based on the Specific Value in a Cell.
    By SolidSmoke in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 10-10-2016, 02:40 PM
  2. [SOLVED] Copy and paste specific cell to another sheet based on multiple criteria
    By impresxy in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-09-2015, 07:11 AM
  3. Copy Paste based on Specific Criteria
    By kittu55 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-06-2015, 08:58 AM
  4. [SOLVED] VBA - Copy and Paste data based on two criteria to specific start row and column
    By ndgo10 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-02-2014, 09:15 AM
  5. [SOLVED] Copy entire row based on 2 criteria and paste on the next blank row on a specific sheet
    By ALNER in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-25-2014, 11:23 PM
  6. Replies: 0
    Last Post: 07-16-2013, 05:22 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

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