VBA help-Look up previous day data and return result

Natalia

Board Regular
Joined
Feb 20, 2009
Messages
72
Hi,

I need your help with a worktask, not a big task. I have reconciliation reports which gets updated each day, so some entries will clear and some will stay and there will be new entries appearing. My team enter their names for the recs they are responsible for as shown in 050511 wkb. The next day when the new report is updated they would have to re-input their names in A6:A to their recs.

I need a macro that will compare current data to previous day if match found then return their names in Col A6:A. This will enable them to see which breaks haven't cleared.

Now there are two tabs "Cash" and "Asset", the asset tab is easy to do a lookup as there is a case number in E6:E, but for cash the macro will need to concatenate in VBA memory a few columns to create a unique ref. So to concatenate cash use B&C&D&E&F&G&H&I&L&M&N, this should do it.

050511 Workbook

Excel Workbook
ABCDEFGHIJKLMNO
5NameGroupCategorySet IDValue DateEntry DateTypeAmountCCYAgeSourceRef1Ref2Ref3Reference
6NatCITIBANKCASH CITIBNPPSITESAPP2-Jun-082-Dec-09SCR4,417.80GBP1019SMP1FUNDS TFRNATL WESTMINSTER BK PLC LONDONSITE ROB GREGOR
7JamesCITIBANKCASH CITIBNPPSITESAPP3-Jun-082-Dec-09SCR2,208.90GBP1018SMP1FUNDS TFRCITIBANK NA LONDONJEFFERY NEIL 3 GOLDERSL
8JohnCITIBANKCASH CITIWTSIE1GBPBNPP20-Dec-1020-Dec-10SCR5,834.29GBP88SMP1NONREFSG1035400992OMTSAMP CAPITAL INVESTORSkjhjhjhjh
9LouiseCITIBANKCASH CITIWTPE2AUSDBNPP23-Dec-1023-Dec-10SCR6,250.00USD85SMP1634SG1035700026OMTSCETERA BROKERS NETWORK, LLC
10JamesCITIBANKCASH CITIWTGDPFEURBNPP24-Jan-1124-Jan-11SDR-2,200,000.00EUR53SMP1FXWTDPFP22SG1102400435OMTSALLEZ AND ASSOCIES SCP MARTIN
Cash


Excel Workbook
ABCDEFGHIJKLM
5NameRecAccountSourceCase No.Value DateSecurity CodeDescriptionCcy CodeLedg StmtUnitsExceptionAge Break
6NatBNPPINTLBNPP.WTPE1AAMP17735374-Apr-11SOLCAUSDSOLYNDRA INC CONVERTIBLE NOTE TRANCHE AUSDLedg1,003,682.00-1,003,682.0029
7JamesBNPPINTLBNPP.WTPE1BAMP17735384-Apr-11SOLCAUSDSOLYNDRA INC CONVERTIBLE NOTE TRANCHE AUSDLedg177,120.00-177,120.0029
8JohnSMPDIAT.DAIAMP27738758-Apr-11AU3CB0173953MEDL 2011-1 A2 6.5PCT 22NOV42Stmt1,000,000.001,000,000.0025
9LouiseSMPCITA.CBASAMP277423412-Apr-11AU000000EQN4EQUINOX MINERALS CDI NPV /ST/010Stmt59,782.0059,782.0021
10LouiseSMPCITA.CBASAMP277423512-Apr-11AU000000CGG3CITADEL RESOURCE GROUP LIMITED NPV /ST/010Stmt854,892.00-854,892.0021
11LouiseSMPNCSX.GESBEAMP277494415-Apr-11NCMNEWCREST MINING LIMITEDAUDLedg465,027.001,200.0018
12LouiseSMPNCSX.GESBEAMP277494415-Apr-11AU000000NCM7NEWCREST MINING LTDAUDStmt466,227.0018
13LouiseSMPJPMT.WHEISSAMP277509718-Apr-11B1FYW63GAGFAH SAEURLedg8,547.00-8,547.0015
14LouiseSMPNCSX.CSLAMP277523319-Apr-11WHGWHK GROUP LIMITEDAUDLedg80,578.00-80,578.0014
15LouiseSMPNCSX.GESSAMP277523219-Apr-11WHGWHK GROUP LIMITEDAUDLedg126,002.00-126,002.0014
Asset


060511 Workbook
Excel Workbook
ABCDEFGHIJKLMNO
5NameGroupCategorySet IDValue DateEntry DateTypeAmountCCYAgeSourceRef1Ref2Ref3Reference
6CITIBANKCASH CITIBNPPSITESAPP2-Jun-082-Dec-09SCR4,417.80GBP1019SMP1FUNDS TFRNATL WESTMINSTER BK PLC LONDONSITE ROB GREGOR
7JP MORGANCASH JPYTYTTYTT12-Aug-107-Nov-10SCR23,434.36BNM345WERYTYTY244544
8CITIBANKCASH CITIBNPPSITESAPP3-Jun-082-Dec-09SCR2,208.90GBP1018SMP1FUNDS TFRCITIBANK NA LONDONJEFFERY NEIL 3 GOLDERSL
9CITIBANKCASH CITIWTSIE1GBPBNPP20-Dec-1020-Dec-10SCR5,834.29GBP88SMP1NONREFSG1035400992OMTSAMP CAPITAL INVESTORSkjhjhjhjh
10CITIBANKCASH CITIWTPE2AUSDBNPP23-Dec-1023-Dec-10SCR6,250.00USD85SMP1634SG1035700026OMTSCETERA BROKERS NETWORK, LLC
11CITIBANKCASH CITIWTGDPFEURBNPP24-Jan-1124-Jan-11SDR-2,200,000.00EUR53SMP1FXWTDPFP22SG1102400435OMTSALLEZ AND ASSOCIES SCP MARTIN
12
Cash


Excel Workbook
ABCDEFGHIJKLM
5NameRecAccountSourceCase No.Value DateSecurity CodeDescriptionCcy CodeLedg StmtUnitsExceptionAge Break
6JP MORGANCITA.CBASCIT12342338-Apr-11EWREWTEWTestNORLedg3,235,325.00-12,155.0021
7BNPPINTLBNPP.WTPE1AJP17735374-Apr-11SOLCAUSDSOLYNDRA INC CONVERTIBLE NOTE TRANCHE AUSDLedg1,003,682.00-1,003,682.0029
8BNPPINTLBNPP.WTPE1BJP17735384-Apr-11SOLCAUSDSOLYNDRA INC CONVERTIBLE NOTE TRANCHE AUSDLedg177,120.00-177,120.0029
9SMPDIAT.DAIJP17738758-Apr-11AU3CB0173953MEDL 2011-1 A2 6.5PCT 22NOV42Stmt1,000,000.001,000,000.0025
10SMPCITA.CBASJP177423412-Apr-11AU000000EQN4EQUINOX MINERALS CDI NPV /ST/010Stmt59,782.0059,782.0021
11SMPCITA.CBASJP177423512-Apr-11AU000000CGG3CITADEL RESOURCE GROUP LIMITED NPV /ST/010Stmt854,892.00-854,892.0021
12SMPNCSX.GESBEJP177494415-Apr-11NCMNEWCREST MINING LIMITEDAUDLedg465,027.001,200.0018
13SMPNCSX.GESBEJP177494415-Apr-11AU000000NCM7NEWCREST MINING LTDAUDStmt466,227.0018
14SMPJPMT.WHEISSJP177509718-Apr-11B1FYW63GAGFAH SAEURLedg8,547.00-8,547.0015
15SMPNCSX.CSLJP177523319-Apr-11WHGWHK GROUP LIMITEDAUDLedg80,578.00-80,578.0014
16SMPNCSX.GESSJP177523219-Apr-11WHGWHK GROUP LIMITEDAUDLedg126,002.00-126,002.0014
17SMPNCSX.GESSJP115151119-Apr-11WHGWHK GROUP LIMITEDAUDLedg126,002.00-54,545.3214
Asset
 
Consider TODAY’s workbook to be the NEW workbook
Consider YESTERDAY’s workbook to be the OLD workbook

The variable rngAssetNew represents a range in the NEW workbook.
The initial range is set to cell “B6”.
Set rngAssetNew = Sheets("Asset").Range("B6")

It then loops until it find finds a cell in column “B” which is empty,
Do Until rngAsetNew=””
‘rest of the code​
Loop​

The same applies to looping through the OLD workbook.
Once the code finds a cell in column "B" which is empty the macro ends.
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Thanks Bertie, i found out what it was if column B has #N/A then the code returned a Type mismatch 13 error.

The macro takes 2 mins to run on full data, the cash has about 3000 rows of data and asset has about 2000, can this be sped up? I tried putting the below but it was still slow.

With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With



Consider TODAY’s workbook to be the NEW workbook
Consider YESTERDAY’s workbook to be the OLD workbook

The variable rngAssetNew represents a range in the NEW workbook.
The initial range is set to cell “B6”.
Set rngAssetNew = Sheets("Asset").Range("B6")
It then loops until it find finds a cell in column “B” which is empty,
<b>
Do Until rngAsetNew=””
‘rest of the code​
Loop​
</b>

The same applies to looping through the OLD workbook.
Once the code finds a cell in column "B" which is empty the macro ends.
 
Upvote 0
Bertie, the highlighted names are not being picked up by the macro when i run the code in 060511

050511 Workbook
Excel Workbook
ABCDEFGHIJKLM
5NameRecAccountSourceCase No.Value DateSecurity CodeDescriptionCcy CodeLedg StmtUnitsExceptionAge Break
6TESTTESTTEST752133TESTTESTTESTTESTTESTTESTTESTTEST
7TESTTESTTEST766330TESTTESTTESTTESTTESTTESTTESTTEST
8MarkTESTTESTTEST767284TESTTESTTESTTESTTESTTESTTESTTEST
9TESTTESTTEST767290TESTTESTTESTTESTTESTTESTTESTTEST
10TESTTESTTEST767290TESTTESTTESTTESTTESTTESTTESTTEST
11DaleTESTTESTTEST767290TESTTESTTESTTESTTESTTESTTESTTEST
12TESTTESTTEST767290TESTTESTTESTTESTTESTTESTTESTTEST
13TESTTESTTEST767291TESTTESTTESTTESTTESTTESTTESTTEST
14TESTTESTTEST767291TESTTESTTESTTESTTESTTESTTESTTEST
15DaleTESTTESTTEST767291TESTTESTTESTTESTTESTTESTTESTTEST
16DaleTESTTESTTEST767295TESTTESTTESTTESTTESTTESTTESTTEST
17TESTTESTTEST767298TESTTESTTESTTESTTESTTESTTESTTEST
Asset



060511 Workbook
Excel Workbook
ABCDEFGHIJKLM
5NameRecAccountSourceCase No.Value DateSecurity CodeDescriptionCcy CodeLedg StmtUnitsExceptionAge Break
6TESTTESTTEST752133TESTTESTTESTTESTTESTTESTTESTTEST
7TESTTESTTEST766330TESTTESTTESTTESTTESTTESTTESTTEST
8MarkTESTTESTTEST767284TESTTESTTESTTESTTESTTESTTESTTEST
9TESTTESTTEST767290TESTTESTTESTTESTTESTTESTTESTTEST
10TESTTESTTEST767290TESTTESTTESTTESTTESTTESTTESTTEST
11TESTTESTTEST767290TESTTESTTESTTESTTESTTESTTESTTEST
12TESTTESTTEST767290TESTTESTTESTTESTTESTTESTTESTTEST
13TESTTESTTEST767291TESTTESTTESTTESTTESTTESTTESTTEST
14TESTTESTTEST767291TESTTESTTESTTESTTESTTESTTESTTEST
15TESTTESTTEST767291TESTTESTTESTTESTTESTTESTTESTTEST
16DaleTESTTESTTEST767295TESTTESTTESTTESTTESTTESTTESTTEST
17TESTTESTTEST767298TESTTESTTESTTESTTESTTESTTESTTEST
Asset
 
Upvote 0
Hi Nat,

Regarding the speed issue.

The quickest way to do this would be to use formula. You mentioned in an earlier post that you could use a vLookup to process the Asset sheet. Have you considered using Index Match to process the Cash sheet?

Use a spare column, i.e., "P" for your concatenation formula.
Place the Index Match formula in column "A".

Excel Workbook
ABCDEFGHIJKLMNOP
5NameGroupCategorySet IDValue DateEntry DateTypeAmountCCYAgeSourceRef1Ref2Ref3Reference*
6NatCITIBANKCASH CITIBNPPSITESAPP02-Jun-0802-Dec-09SCR4,417.80GBP1019SMP1FUNDS TFRNATL WESTMINSTER BK PLC LONDONSITE ROB GREGOR*CITIBANKCASH CITIBNPPSITESAPP39601401494417.8GBPSMP1FUNDS TFRSITE ROB GREGOR
Cash


This will certainly be quicker than looping through thousands of rows.

I will be away for the rest of the day (Christening). I will look at the other issues when I get back.
 
Upvote 0
Hi Bertie,

I have no issue in using formula but this task is daily and i want to avoid manual input of formulas everyday. I like the idea of the macro asking to choose file and then the code compares the data.

If there is Vba method that can use formula input and allow the choosing of file then i would welcome that method.
 
Upvote 0
Hi Nat,

To speed up the macro I have taken out the second loop and used the FIND method instead.

This works fine with the ASSET sheet as it has a unique identifier in column "E", CASE NO. If this is found we get the row it is on and update the username from column "A" on the same row.

The only way this will work for the CASH sheet will be if there is a unique identifier here also. For testing I have used column "P" to hold the concatenation string derived from a formula; see my earlier post. This column can be hidden. Again, if a match is found we get the username from comumn "A" on the same row.

Code:
[COLOR=darkblue]Sub[/COLOR] CompareStrings()
   [COLOR=darkblue]Dim[/COLOR] wbOld [COLOR=darkblue]As[/COLOR] Workbook
   [COLOR=darkblue]Dim[/COLOR] sMatch [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
   [COLOR=darkblue]Dim[/COLOR] rngAssetNew [COLOR=darkblue]As[/COLOR] Range
   [COLOR=darkblue]Dim[/COLOR] rngCashNew [COLOR=darkblue]As[/COLOR] Range
   [COLOR=darkblue]Dim[/COLOR] FileToOpen
   [COLOR=darkblue]Dim[/COLOR] rngRow As Range
 
   [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]GoTo[/COLOR] errCompareStrings
 
   [COLOR=green]'============================================[/COLOR]
   [COLOR=green]'set up the worksheet ranges to loop through[/COLOR]
   [COLOR=green]'============================================[/COLOR]
   [COLOR=darkblue]Set[/COLOR] rngAssetNew = Sheets("Asset").Range("B6")
   [COLOR=darkblue]Set[/COLOR] rngCashNew = Sheets("Cash").Range("B6")
 
   FileToOpen = Application.GetOpenFilename("Excel Files (*.xl*), *.xl*")
   [COLOR=darkblue]If[/COLOR] FileToOpen <> [COLOR=darkblue]False[/COLOR] [COLOR=darkblue]Then[/COLOR]
      [COLOR=darkblue]Set[/COLOR] wbOld = Workbooks.Open(FileToOpen)
   [COLOR=darkblue]Else[/COLOR]
      MsgBox "No file Selected"
      [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Sub[/COLOR]
   [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
 
   [COLOR=green]'================[/COLOR]
   [COLOR=green]'asset worksheet[/COLOR]
   [COLOR=green]'================[/COLOR]
   [COLOR=darkblue]Do[/COLOR] [COLOR=darkblue]Until[/COLOR] rngAssetNew = ""
      sMatch = Trim(rngAssetNew.Offset(0, 3).Value)
 
      [COLOR=green]'in case no match is found[/COLOR]
      [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]Resume[/COLOR] [COLOR=darkblue]Next[/COLOR]
         [COLOR=darkblue]With[/COLOR] wbOld.Sheets("Asset")
[COLOR=red]         Set rngRow = .Columns(5).Find( _[/COLOR]
[COLOR=red]            What:=sMatch, _[/COLOR]
[COLOR=red]            After:=.Cells(5, 5), _[/COLOR]
[COLOR=red]            LookIn:=xlValues, _[/COLOR]
[COLOR=red]            LookAt:=xlPart, _[/COLOR]
[COLOR=red]            SearchOrder:=xlByColumns, _[/COLOR]
[COLOR=red]            SearchDirection:=xlNext, _[/COLOR]
[COLOR=red]            MatchCase:=False, _[/COLOR]
[COLOR=red]            SearchFormat:=False)[/COLOR]
 
            [COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] rngRow [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
               rngAssetNew.Offset(0, -1).Value = .Range("A" & rngRow.Row).Value
            [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
         [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
      [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]GoTo[/COLOR] 0
 
      [COLOR=green]'next entry[/COLOR]
      [COLOR=darkblue]Set[/COLOR] rngAssetNew = rngAssetNew.Offset(1, 0)
   [COLOR=darkblue]Loop[/COLOR]
[COLOR=green]'Stop[/COLOR]
   '================
   [COLOR=green]'cash worksheet[/COLOR]
   [COLOR=green]'================[/COLOR]
   [COLOR=darkblue]Do[/COLOR] [COLOR=darkblue]Until[/COLOR] rngCashNew = ""
      sMatch = Trim(rngCashNew.Offset(0, 14).Value)
      [COLOR=green]'in case no match is found[/COLOR]
      [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]Resume[/COLOR] [COLOR=darkblue]Next[/COLOR]
         [COLOR=darkblue]With[/COLOR] wbOld.Sheets("[COLOR=red]Cash")[/COLOR]
            [COLOR=darkblue]Set[/COLOR] rngRow = .Columns[COLOR=red](16).[/COLOR]Find( _
               What:=sMatch, _
               After:=.Cells([COLOR=red]5, 16),[/COLOR] _
               LookIn:=xlValues, _
               LookAt:=xlPart, _
               SearchOrder:=xlByColumns, _
               SearchDirection:=xlNext, _
               MatchCase:=False, _
               SearchFormat:=False)
 
            [COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] rngRow [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
               rngCashNew.Offset(0, -1).Value = .Range("A" & rngRow.Row).Value
            [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
         [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
      [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]GoTo[/COLOR] 0
 
      [COLOR=green]'next entry[/COLOR]
      [COLOR=darkblue]Set[/COLOR] rngCashNew = rngCashNew.Offset(1, 0)
   [COLOR=darkblue]Loop[/COLOR]
 
exitCompareStrings:
   [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]Resume[/COLOR] [COLOR=darkblue]Next[/COLOR]
 
  [COLOR=green]' wbOld.Close SaveChanges:=False[/COLOR]
   [COLOR=darkblue]Set[/COLOR] wbOld = [COLOR=darkblue]Nothing[/COLOR]
   [COLOR=darkblue]Set[/COLOR] rngAssetNew = [COLOR=darkblue]Nothing[/COLOR]
   [COLOR=darkblue]Set[/COLOR] rngCashNew = [COLOR=darkblue]Nothing[/COLOR]
   [COLOR=darkblue]Set[/COLOR] rngRow = [COLOR=darkblue]Nothing[/COLOR]
   [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Sub[/COLOR]
errCompareStrings:
   MsgBox "Error: " & Err.Number & vbCrLf & _
         "Description: " & Err.Description
   [COLOR=darkblue]Resume[/COLOR] exitCompareStrings:
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Upvote 0
Hi Bertie,

This is heaps faster, it took 12 seconds when i added the screenupdating etc.

I have implemented the concatenation column and this is hidden.

Thanks for your time and help on this task :)
 
Upvote 0
Hi Bertie,

How can the below be amended to lookup two columns and return result in one worksheet. So return result in Col A and Col B. Unique identifier is Col I, i tried amending your code but it didn't return all result in Col B, missed a few comments. I have provided to screen shots below, one shows previous day data and the other today data.

Excel Workbook
ABCDEFGHI
4Previous Day
5NameCommentsPfolioBrokerContractDateSettleDateDaysOutstandingEntryDateTransID
6JoeTest1WSTIEFDIV2-Jul-096-Jul-096952-Jan-1023943
7PISIFETAKEOV6-Aug-1013-Aug-103026-Aug-104592611
8PISIFETAKEOV6-Aug-1013-Aug-103026-Aug-104592612
92YEMXEDIV13-Sep-1011-Oct-102332-Jan-11267310
102EMXXSDIV13-Sep-1011-Oct-102332-Jan-11267253
11JamesTest22YEGXEDIV27-Sep-1012-Oct-102322-Jan-11267307
12JamesTest32YEGXEDIV27-Sep-1012-Oct-102322-Jan-11267317
13JamesTest42EGXXSDIV27-Sep-1012-Oct-102322-Jan-11267242
14JamesTest52EGXXSDIV27-Sep-1012-Oct-102322-Jan-11267316
15OPSINNDIV24-Feb-1118-May-111424-Feb-114923781
Asset


Excel Workbook
ABCDEFGHI
5NameCommentsPfolioBrokerContractDateSettleDateDaysOutstandingEntryDateTransID
6WSTIEFDIV2-Jul-096-Jul-096952-Jan-1023943
7PISIFETAKEOV6-Aug-1013-Aug-103026-Aug-104592611
8PISIFETAKEOV6-Aug-1013-Aug-103026-Aug-104592612
92YEMXEDIV13-Sep-1011-Oct-102332-Jan-11267310
102EMXXSDIV13-Sep-1011-Oct-102332-Jan-11267253
112YEGXEDIV27-Sep-1012-Oct-102322-Jan-11267307
122YEGXEDIV27-Sep-1012-Oct-102322-Jan-11267317
132EGXXSDIV27-Sep-1012-Oct-102322-Jan-11267242
142EGXXSDIV27-Sep-1012-Oct-102322-Jan-11267316
15OPSINNDIV24-Feb-1118-May-111424-Feb-114923781
Asset









Code:
  '============================================
   'set up the worksheet ranges to loop through
   '============================================
 
   Set rngAssetNew = Sheets("Asset").Range("C6")

 
   FileToOpen = Application.GetOpenFilename("Excel Files (*.xl*), *.xl*")
   If FileToOpen <> False Then
      Set wbOld = Workbooks.Open(FileToOpen)
   Else
      MsgBox "No file Selected"
      Exit Function
   End If
 
   '================
   'asset Worksheet
   '================
   Do Until rngAssetNew = ""
      sMatch = Trim(rngAssetNew.Offset(0, 6).Value)

      'in case no match is found
      On Error Resume Next
         With wbOld.Sheets("Asset")
         Set rngRow = .Columns(9).Find( _
            What:=sMatch, _
            After:=.Cells(5, 9), _
            LookIn:=xlValues, _
            LookAt:=xlPart, _
            SearchOrder:=xlByColumns, _
            SearchDirection:=xlNext, _
            MatchCase:=False, _
            SearchFormat:=False)

            If Not rngRow Is Nothing Then
               rngAssetNew.Offset(0, -2).Value = .Range("A" & rngRow.Row).Value
            End If
         End With
      On Error GoTo 0

      'next entry

   Loop

   Do Until rngAssetNew = ""
     Set rngAssetNew = rngAssetNew.Offset(1, 0)
            sMatch = Trim(rngAssetNew.Offset(0, 6).Value)

      'in case no match is found
      On Error Resume Next
         With wbOld.Sheets("Asset")
         Set rngRow = .Columns(9).Find( _
            What:=sMatch, _
            After:=.Cells(5, 9), _
            LookIn:=xlValues, _
            LookAt:=xlPart, _
            SearchOrder:=xlByColumns, _
            SearchDirection:=xlNext, _
            MatchCase:=False, _
            SearchFormat:=False)

            If Not rngRow Is Nothing Then
               rngAssetNew.Offset(0, -1).Value = .Range("B" & rngRow.Row).Value
            End If
         End With
      On Error GoTo 0

      'Next entry
      Set rngAssetNew = rngAssetNew.Offset(1, 0)
   Loop
 
Upvote 0

Forum statistics

Threads
1,224,547
Messages
6,179,436
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top