View Single Post
 
Old 12-05-2016, 10:06 AM
cinstanl cinstanl is offline Windows 7 64bit Office 2016
Novice
 
Join Date: Dec 2016
Posts: 3
cinstanl is on a distinguished road
Default Using If function in VBA to match data from two sheets

I have a workbook that I have already added code to, but I believe it is taking and doing a partial match... so if the data for example... 1584 on the Aging report.... matching....Inv: 10215849-RI on job costs.because of the middle numbers.. it is bringing the data over from JobCosts and placing it in V on the Aging... this is incorrect, the invoice numbers have to be an exact match... I have highlighted a few examples.... the ones in Yellow do not have a matching invoice number in column K on the JobCosts worksheet... I think if we can edit the code to state that Column L (12) on JobCost also needs to match Columns R on the Aging .


Code:
Sub MatchInvNo()
'ActiveWorkbook.RefreshAll

   Dim SrcWS        As Worksheet
   Dim TgtWS        As Worksheet
   Dim TgtRng       As Range
   Dim TgtCel       As Range
   Dim LR           As Long
   Dim myInv        As Range
   Set SrcWS = Sheets("JOBCOST")
   Set TgtWS = Sheets("AGING")

   With TgtWS
      LR = .Range("E" & .Rows.Count).End(xlUp).Row
      Set TgtRng = .Range("E2:E" & LR)
      For Each TgtCel In TgtRng

         Set myInv = SrcWS.Columns(11).Find(TgtCel.Value, , xlValues, xlPart, xlByRows, xlNext, False)
         If Not myInv Is Nothing Then
            .Cells(TgtCel.Row, "V").Value = SrcWS.Cells(myInv.Row, "F").Value
         End If
      Next TgtCel
   End With
End Sub
Attached Files
File Type: zip EXCELFORUMASSIST1.zip (1.06 MB, 13 views)
Reply With Quote