Results 1 to 7 of 7

My FindNext is not working

Threaded View

  1. #1
    Registered User
    Join Date
    08-12-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    24

    My FindNext is not working

    I am trying to find the details from two columns based on the text string in a third column from two separate excel files
    The code should search file B column C for a match as listed in column A from the code sheet (file A).
    When it finds a matching word, it then copies details from file B, column D at the correct row into file A column B and also column F to column C (file B to file A).

    It works for finding the first string, but if there is more than one entry of the same name in file B, it fails. (there is only one instance of the same name).
        If VBA.Dir(textFile) = "" Then
            MsgBox "File " & textFile & " doesn't exist."
            End
        End If
    
        
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        
        
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        On Error Resume Next
            Workbooks(objFSO.GetBaseName(textFile)).Close SaveChanges:=False
            Workbooks.Open Filename:=textFile
        On Error GoTo 0
        textFileName = ActiveWorkbook.Name
      
      
        Workbooks(origFileName).Activate
        Set objRange = Columns("A")
        lLastRow = objRange.Cells(Rows.Count).End(xlUp).Row
        
        For iloop = 2 To lLastRow
            Workbooks(origFileName).Activate
            searchString = ActiveSheet.Cells(iloop, 1)
            fgetRowNumber = 0
            If searchString <> "" Then
                    Workbooks(textFileName).Activate
                    If Right$(partName, 1) = "D" Then
                        On Error Resume Next
                            fgetRowNumber = ActiveSheet.Cells(1, 3).EntireColumn.Find(What:=searchString, SearchOrder:=xlByRows, SearchDirection:=xlDown, MatchCase:=False).Row
                            Set fgetRowNumber = ActiveSheet.Columns(3).FindNext(fgetRowNumber)
                        On Error GoTo 0
                    Else
                        On Error Resume Next
                            fgetRowNumber = ActiveSheet.Cells(1, 3).EntireColumn.Find(What:=searchString, SearchOrder:=xlByRows, SearchDirection:=xlDown, MatchCase:=False).Row
                        On Error GoTo 0
                    End If
                
                If fgetRowNumber > 0 Then
                    partName = ActiveSheet.Cells(fgetRowNumber, 4)
                    partRev = ActiveSheet.Cells(fgetRowNumber, 6)
                    Workbooks(origFileName).Activate
                    ActiveSheet.Cells(iloop, 2) = partName
                    ActiveSheet.Cells(iloop, 3) = partRev
                Else
                    Workbooks(origFileName).Activate
                    ActiveSheet.Cells(iloop, 2) = ""
                    ActiveSheet.Cells(iloop, 3) = ""
                End If
            End If
        Next
      
        On Error Resume Next
            Workbooks(textFileName).Close SaveChanges:=False
        On Error GoTo 0
        Workbooks(origFileName).Activate
      
        Application.DisplayAlerts = True
        Application.ScreenUpdating = True
    Last edited by tmd_63; 12-02-2013 at 11:15 AM. Reason: missed the code tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. .FindNext not working in UDF
    By magnusga in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-20-2013, 12:57 PM
  2. [SOLVED] vba .findnext gives 'nothing'
    By Maaike... in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-17-2012, 10:57 AM
  3. FindNext
    By ddbusiness in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-28-2010, 03:54 AM
  4. [SOLVED] Findnext not working
    By bjwade62 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-16-2006, 10:08 PM
  5. Findnext
    By Noemi in forum Excel General
    Replies: 1
    Last Post: 12-12-2005, 07:30 AM

Tags for this Thread

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