Results 1 to 6 of 6

Vba vlookups

Threaded View

Kiichiro Vba vlookups 01-08-2016, 12:39 PM
protonLeah Re: Vba vlookups 01-08-2016, 06:43 PM
Kiichiro Re: Vba vlookups 01-09-2016, 02:21 AM
gbeats101 Re: Vba vlookups 01-09-2016, 03:08 AM
gbeats101 Re: Vba vlookups 01-09-2016, 05:59 PM
Kiichiro Re: Vba vlookups 01-10-2016, 06:54 AM
  1. #1
    Registered User
    Join Date
    12-20-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    5

    Vba vlookups

    Hello all, I'm wanting to have a system where a user presses a button that opens up a prompt to scan product and if it exists on list B than it copies some data to Sheet 1 A and B. But if it is already on Sheet 1 in A or B to delete it. I have gotten pretty much everything working.

    The thing is I have it so it will add everything using any empty spaces first, and if it is on the list it will also be removed. But the problem is, is I have no idea how to make it do a VLOOKUP to see if that product already exists or not.

    Take for instance I add the following parts

    Glue
    Staples
    High powered rifle

    If I scan Glue again it removes it just fine, but if I scan a high powered rifle it will add it to the first slot despite already being on the list.

    *Note these are not my actual products*

    Some script I already have

    Private Sub CommandButton1_Click()
    
    Dim product As String 'Sets product number as a string
    Dim Sheet2Product As String
    Dim i As Integer
    Dim match As Boolean
    Dim rng As Range
    Set rng = Sheet1.Range("A:A")
    Dim empty1 As Boolean
    i = 1
    Dim Zone As Integer
    Dim duplicate As Boolean
    vlookup:
    
    
    product = InputBox("product Number :") 'Sets what is being checked as an product number
    Debug.Print "Get product number"
    If IsEmpty(product) = False Then 'makes sure that the field is not empty
        Debug.Print "Check if product number is empty"
        Sheet2Product = Application.WorksheetFunction.vlookup(product, Sheet2.Range("B:D"), 1, False)
        Zone = Application.WorksheetFunction.vlookup(product, Sheet2.Range("B:D"), 2, False)
        Debug.Print "Check to see if the product number matches"
    End If
            If product = Sheet2Product Then
            match = True
            Else
            match = False
            End If
    
    DuplicateCheck:
                If Sheet2Product = Application.WorksheetFunction.vlookup(product, rng, 1, False) = True Then
                duplicate = True
                Else
                duplicate = False
                End If
                
                
    
    EmptyCheck:
                If IsEmpty(Sheet1.Cells(i, 1)) = True Then
                empty1 = True
                Else
                empty1 = False
                End If
                If empty1 = False Then
                If product = Sheet1.Cells(i, 1) Then
                Sheet1.Cells(i, 1) = ""
                Sheet1.Cells(i, 2) = ""
                MsgBox ("Removed " & product)
                Else
                i = i + 1
                GoTo EmptyCheck
                End If
                End If
                If empty1 = True Then
                Sheet1.Cells(i, 1) = product
                Sheet1.Cells(i, 2) = Zone
                MsgBox ("Added " & product)
                End If
                
                
    
    Exit Sub
    myerror:
        MsgBox ("Sheet2Product Not found!")
        
    End Sub
    Also please keep in mind I only started learning this about 15-16 hours ago so I'm probably doing everything inefficiently
    Last edited by Kiichiro; 01-08-2016 at 12:44 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. IF THEN and VLOOKUPS Together
    By degross77 in forum Excel General
    Replies: 3
    Last Post: 11-20-2014, 05:27 PM
  2. Need help on Vlookups
    By Brian13 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-05-2014, 11:50 AM
  3. Excel 2007 : vlookups
    By Cerena in forum Excel General
    Replies: 17
    Last Post: 05-29-2012, 01:02 AM
  4. [SOLVED] Vlookups
    By chris.slater in forum Excel General
    Replies: 1
    Last Post: 03-15-2012, 02:34 PM
  5. Vlookups
    By imageres in forum Excel General
    Replies: 1
    Last Post: 02-09-2011, 05:26 AM
  6. [SOLVED] VLOOKUPS
    By Brett in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-22-2006, 09:55 AM
  7. [SOLVED] vlookups
    By T in forum Excel General
    Replies: 4
    Last Post: 05-13-2006, 07:15 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