+ Reply to Thread
Results 1 to 3 of 3

Vlookup Customer List issues

Hybrid View

  1. #1
    Registered User
    Join Date
    01-31-2017
    Location
    Chester
    MS-Off Ver
    2013
    Posts
    26

    Vlookup Customer List issues

    Hi, I have a database in Excel. Each sheet from the workbook acts as a single record. I have a Vlookup in place that checks a hidden worksheet called Contractor List and it checks which contractor is active or inactive.

    The issue I have is that it messes up the Search VBA I have. I located the record but when asked for a further search, if you select NO, it flips onto another record. Is there any way to stop this?

    Many thanks,

    Jaime.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,024

    Re: Vlookup Customer List issues

    Think you might need to share the code and, ideally, a sample workbook.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-31-2017
    Location
    Chester
    MS-Off Ver
    2013
    Posts
    26

    Re: Vlookup Customer List issues

    Hi, here there

    Here it is:
    Dim sheetCount As Integer
    Dim datatoFind
    Sub Button1_Click()
    
    Find_Data
    
    End Sub
    Private Sub Find_Data()
        Dim counter As Integer
        Dim currentSheet As Integer
        Dim notFound As Boolean
        Dim yesNo As String
    
        notFound = True
    
        On Error Resume Next
        currentSheet = ActiveSheet.Index
        datatoFind = StrConv(InputBox("Please enter the Glen Dimplex Contractor Name to search for"), vbLowerCase)
        If datatoFind = "" Then Exit Sub
        sheetCount = ActiveWorkbook.Sheets.Count
        If IsError(CDbl(datatoFind)) = False Then datatoFind = CDbl(datatoFind)
        For counter = 1 To sheetCount
            Sheets(counter).Activate
    
            Cells.Find(What:=datatoFind, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
    
            If InStr(1, StrConv(ActiveCell.Value, vbLowerCase), datatoFind) Then
                notFound = False
                If HasMoreValues(counter) Then
                    yesNo = MsgBox("Do you want to continue search?", vbYesNo)
                    If yesNo = vbNo Then
                        Sheets(counter).Activate
                        Exit For
                    End If
                Else
                    Sheets(counter).Activate
                    Exit For
                End If
                Sheets(counter).Activate
            End If
        Next counter
        If notFound Then
            MsgBox ("Record not found")
            Sheets(currentSheet).Activate
        End If
    End Sub
    Private Function HasMoreValues(ByVal sheetCounter As Integer) As Boolean
        HasMoreValues = False
        Dim str As String
        Dim lastRow As Long
        Dim lastCol As Long
        Dim rRng  As Excel.Range
    
        For counter = sheetCounter + 1 To sheetCount
            Sheets(counter).Activate
    
            lastRow = ActiveCell.SpecialCells(xlLastCell).Row
            lastCol = ActiveCell.SpecialCells(xlLastCell).Column
    
            For vRow = 1 To lastRow
                For vCol = 1 To lastCol
                    str = Sheets(counter).Cells(vRow, vCol).Text
                    If InStr(1, StrConv(str, vbLowerCase), datatoFind) Then
                        HasMoreValues = True
                        Exit For
                    End If
                Next vCol
    
                If HasMoreValues Then
                    Exit For
                End If
            Next vRow
    
            If HasMoreValues Then
                Sheets(sheetCounter).Activate
                Exit For
            End If
        Next counter
    End Function
    Many thanks in advance

    Jaime
    Last edited by jeffreybrown; 02-04-2017 at 12:23 PM. Reason: Please used code tags when posting code!

+ 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. Replies: 2
    Last Post: 10-13-2015, 07:58 PM
  2. Data Validation List Issues/Sorting Issues
    By taylorbe in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-12-2014, 09:53 AM
  3. [SOLVED] Using Data Validation List to update customer address list
    By Rosco88 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-29-2014, 10:27 AM
  4. [SOLVED] Top 5 List (LARGE and VLOOKUP Issues)
    By alexrawnsley in forum Excel General
    Replies: 3
    Last Post: 07-02-2012, 02:30 AM
  5. sorting a list of customer invoices from columns into rows / customer
    By jr1984 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2011, 07:04 AM
  6. Customer Names into Customer List
    By dustin470 in forum Excel General
    Replies: 2
    Last Post: 02-13-2010, 08:52 AM
  7. [SOLVED] How To Make A Customer List With Extra Entries Per Customer
    By Minitman in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-31-2005, 03:43 PM

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