+ Reply to Thread
Results 1 to 2 of 2

VBA to copy and paste data based on lookup criteria to select and position data

Hybrid View

  1. #1
    Registered User
    Join Date
    03-20-2018
    Location
    Cambs
    MS-Off Ver
    2010 +
    Posts
    21

    VBA to copy and paste data based on lookup criteria to select and position data

    Hi,

    Outline of required code relating to the attachment. I managed small sections of the code but not the lookup and position based on criteria.

    For each cell in Col F

    <On Chk log test tab>
    Check if Col F is blank.
    If yes go to Col C and copy date.
    Check site number and

    On Tracker Test tab
    Match to site number in Col A on Tracker test tab.
    Find next empty cell on matched row
    Paste the date copied

    On Chk log test tab
    Place "logged" in Col F.

    Else if Col F = "logged"
    Then move to next cell.
    Last edited by BvDA; 04-24-2018 at 07:33 AM.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: VBA to copy and paste data based on lookup criteria to select and position data

    You didn't give any complete examples in your book, so I hope this is what you wanted.

    Sub MatchData()
    
    Dim WS As Worksheet
    Dim WSTrk As Worksheet
    Dim A As Long
    Dim LastRow As Long
    Dim LC As Long
    Dim C As Range
    
    Set WS = Worksheets("Chk log test")
    Set WSTrk = Worksheets("Tracker test")
    
    With WSTrk
        LR = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With
    
    
    With WS
        'Last row on Chk Log Test
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        
        For A = 2 To LastRow
            If .Cells(A, "F") = "" Then
                With WSTrk.Range("A1:A" & LR)
                    Set C = .Find(WS.Cells(A, "A"), , xlValues)
                    If Not C Is Nothing Then
                        'Find next column on Tracker
                        LC = LastNonZero(C.Row)
                        'Test to make sure the functino returned a number > 2 & < Max column
                        If LC > 2 Then
                            'post date
                            WSTrk.Cells(C.Row, LC) = WS.Cells(A, "C")
                            WS.Cells(A, "F") = "LOGGED"
                        End If
                    End If
                End With
            End If
        Next
            
    End With
    
    
    End Sub
    
    Function LastNonZero(aRow As Long) As Long
    
    Dim J As Long
    
    J = 3
    
    Do Until Worksheets("Tracker test").Cells(aRow, J).Value = ""
        If J < Worksheets("Tracker test").Columns.Count Then
            J = J + 1
        Else
            LastNonZero = 0
            Exit Function
        End If
    Loop
    
    LastNonZero = J
    
    End Function
    Attached Files Attached Files
    David
    (*) Reputation points appreciated.

+ 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. Copy and paste data based on criteria from row and columns
    By rz6657 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-04-2015, 03:33 PM
  2. Copy and Paste data based on two criteria being met
    By btxp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-04-2013, 02:24 PM
  3. Copy / Paste Data Based on Changing Criteria
    By ccowman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-09-2012, 04:47 PM
  4. [SOLVED] Copy, paste data based on a particular criteria
    By bonny24tycoon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-01-2012, 03:08 PM
  5. Copy Data Based on Criteria and Paste In Next Blank Row
    By Gingeiko in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-30-2011, 02:28 AM
  6. Copy and paste data based on criteria
    By rhudgins in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-15-2010, 06:45 PM
  7. Copy paste data based on criteria in a loop
    By rhudgins in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-24-2010, 08:14 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