Error in finding a row number within a for loop

  • I am running a code that will go through a list of PortNames and find the one corresponding to the PortName in another list in a different workbook. The corresponding PortName will then use the find function to find the row number that corresponds to that particular PortName. I am running into trouble on this piece of code:

    Code
    AssetAllocateRow = assetAllocate.Sheets("Asset_Allocation").Range(assetAllocate.Sheets("Asset_Allocation").Cells(1, 1), assetAllocate.Sheets("Asset_Allocation").Cells(numAssetAllocateRows, 1)).Find(PortName, LookIn:=xlValues, lookat:=xlWhole).Row



    This is the full code leading up to that statement:


  • Re: Error in finding a row number within a for loop


    you need to use syntax like this:


    Code
    Dim SrchVal              As Range
     Dim myRow              As Long
    
    
     Set  SrchVal = assetAllocate.Sheets("Asset_Allocation").Range(assetAllocate.Sheets("Asset_Allocation").Cells(1, 1), assetAllocate.Sheets("Asset_Allocation").Cells(numAssetAllocateRows, 1)).Find(PortName, , xlValues, xlPart, xlByRows, xlNext, False)
     myRow = SrchVal.Row

    Matt Mickle
    Using Excel 2010,2013 & 2016

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!