Results 1 to 4 of 4

VBA Multiple Criteria and VLoopUp

Threaded View

  1. #1
    Registered User
    Join Date
    09-11-2016
    Location
    Copenhagen
    MS-Off Ver
    2016
    Posts
    3

    VBA Multiple Criteria and VLoopUp

    Hi Guys,

    Im am trying to make a code that can help me automate the making of contracts. Im on the right track but it seems like it's still lacking a bit of code.

    In plain English this is want my code to do:

    1: Read the variable "AptCode" and check if is the C-column on sheet shTenants
    2: If AptCode is found in in the C-column test if that same line has the "ACTIVE" status found in Column F in shTenants
    3: If both of the conditions are met, being AptCode and Active, then VLookup and print Tenant_Name and FavColor to cell A5:G9
    4: Loop for all matches

    I would like the the code to return the following:

    "Batman likes the color Black, and Barbie Girl likes the color Pink"

    Problem no.1: Crocodile Dundee no longer lives in the apartment since the status has been marked as TERMINATED
    Problem no.2: The code only writes the data of Batman and not of Barbie Girl. It lacks the loop.


    Can you guys help me? This is my very first VBA project!

    Here's my code:


    Option Explicit
    Sub ContractGenerator2()
    
    'Defining variables BEGIN
        Dim AptCode As Long
            AptCode = shContract.Cells(4, 3)
        Debug.Print AptCode
        
        Dim Last_Row As Long
            Last_Row = shTenants.Cells(shTenants.Rows.Count, 1).End(xlUp).Row
        Debug.Print Last_Row
            
                Dim iRange As Long
                    For iRange = 2 To Last_Row
                                            
        Dim Tenant_Names As String
            Tenant_Names = Application.VLookup(AptCode, shTenants.Range("C:F"), 2, False)
        Debug.Print Tenant_Names
        
        Dim FavColor As String
            FavColor = Application.VLookup(AptCode, shTenants.Range("C:F"), 3, False)
        Debug.Print FavColor
    'Defining variables END
    
    
    'Code BEGIN
      
                If shTenants.Range("C" & iRange).Value = AptCode Then
                    If shTenants.Range("F" & iRange).Value = "ACTIVE" Then
                    shContract.Range("A5:G6") = Tenant_Names & " likes the color " & FavColor
                    End If
                End If
            Next
    End Sub
    
    'Code END
    Attached Files Attached Files
    Last edited by JacobRavn; 07-28-2018 at 01:02 PM. Reason: Solved

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Want to use 2 IF, IS BLANK, VLOOPUP together
    By anilanilpatni in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-08-2017, 03:42 AM
  2. [SOLVED] VLOOPUP Formula help
    By bordemkills in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-28-2017, 01:23 AM
  3. [SOLVED] aSSISTANCE WITH ROW DELETE BASED ON MULTIPLE VLOOPUP CRITERIA FROM ANOTHER WORKBOOK
    By sintek in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-21-2016, 04:34 PM
  4. [SOLVED] Index, Match, or VLoopup? Returning a table value based on criteria from two drop down's
    By jkwlvsky in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-18-2015, 06:40 PM
  5. Multiple VLOOPUP Values and Criteria
    By Thomasdaddy1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-15-2013, 02:20 PM
  6. Vloopup VBA help
    By craigmck in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-17-2011, 10:59 AM
  7. [SOLVED] VLOOPUP
    By Fran in forum Excel General
    Replies: 6
    Last Post: 06-08-2006, 09:25 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