+ Reply to Thread
Results 1 to 12 of 12

Integrating VLookup in a program

  1. #1
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Integrating VLookup in a program

    Hello,

    I'm having difficulties expanding the following program:

    PHP Code: 
    Sub Demo2()
       
    DDim Rs As RangeRgRz As RangeC&, A$, Rf As Rangel&, R&

    Dim LoB As String

    Dim OrgWsName 
    As String
    Dim DstWsName 
    As String

            OrgWsName 
    firm
            
            DstWsName 
    "BT_" firm

        
       Set Rs 
    Worksheets(OrgWsName).UsedRange
       Set Rg 
    Rs.Find("Summe", , xlValuesxlWholexlByRows)
        If 
    Rg Is Nothing Then
            Beep
        
    Else
                
    Rg.CurrentRegion.Columns.Count 1
                l 
    2
            With Worksheets
    (DstWsName)
                    
    '.Range("A2:A300,C2:O300").Clear
                    Application.ScreenUpdating = False
                    A = Rg.Address
                Do
                   Set Rf = Rg.End(xlUp).End(xlUp)
                        l = l + 1
                   LoB = Application.WorksheetFunction.VLookup(Rf.Value, Worksheets(OrgWsName).Range("A15:C15"), 3, False).Value
                    If Rg.Row > R Then
                        l = l + 1
                        R = Rg.Row
                      [COLOR="#FF0000"] .Cells(l, 1).Value = Rf.Value[/COLOR]
                       .Cells(l, 2).Value = LoB
                    End If
                       .Cells(l, 3).Value = Rf(0).Value
                           Rg(1, 2).Resize(, C).Copy .Cells(l, 4)
                       Set Rg = Rs.FindNext(Rg)
                Loop Until Rg.Address = A
                       Set Rg = Nothing:  Set Rf = Nothing
                   .UsedRange.Font.Bold = False
            End With
                    Application.ScreenUpdating = True
        End If

       Set Rs = Nothing
    End Sub 
    In column 1, we have a code line which writes data in the sheet DstWsName (see red line in the code):

    Please Login or Register  to view this content.
    I want to expand the program, so that it creates in the cell next to this cell (same row, column 2) a vlookup which checks if the value in .Cells(l, 1) in the sheet DstWsName is in the Range A15:C15 in the sheet OrgWsName and returns the corresponding value from the column C.

    I've tried:

    Please Login or Register  to view this content.
    This returns a “Unable to get the VLookup property of the WorksheetFunction Class” error. Do you know what could be the problem?

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Integrating VLookup in a program


    Hi !

    Try first without WorksheetFunction (useless) but just with Application and the variable type must be Variant in case of any error.

  3. #3
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Re: Integrating VLookup in a program

    Hello Marc,

    I've made the suggested changes. Now I get a "object required" error (424) at the line:

    Please Login or Register  to view this content.
    LoB is defined as variant now.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Integrating VLookup in a program


    Check each variable within this codeline and objects as well …

  5. #5
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Re: Integrating VLookup in a program

    The problem seems to be now:

    Please Login or Register  to view this content.
    But I can't see why.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation


    Is LoB an object ?‼ You even no need it as you can directly apply the VLookup to the cell property …

  7. #7
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Re: Integrating VLookup in a program

    Hello Marc,

    thank you for your answer. I have uploaded a sample and took your advice and defined the VLookup directly on the cell.

    The problem is, that Vlookup doesn't find any values. For instance, I'm looking for the Rf.Value = 1 in the range A15:C15 of the sheet "AZ". I'd expect it to return the value in C3 "AZ\O2_Life",
    because we have in A3 the value "1". The Vlookup produces a "NV"-error. I don't understand why.
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Integrating VLookup in a program


    Check manually within a cell a VLookup formula as VLookup returns an error when not found with its False third parameter …

  9. #9
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Re: Integrating VLookup in a program

    I did that, Vlookup as a formula works well.

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Integrating VLookup in a program


    As I can't guess what exactly is your manual formula …

  11. #11
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Re: Integrating VLookup in a program

    I've tried a few things and noticed that the code works, if the range where the vlookup searches, contains no empty rows. In my example, A2:C2 is empty and this leads to the error. If I run the VLookup on A3:C15, the code works. Is this normal?

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Integrating VLookup in a program


    It should be normal if a VLookup formula within a cell does the same as well …

+ 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. VBA Program integrating Publisher Mail Merge and Excel Spreadsheet
    By SBBmaster09 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-08-2015, 04:12 AM
  2. Program a VLOOKUP formula
    By mma3824 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2014, 04:44 PM
  3. Replies: 5
    Last Post: 01-10-2012, 05:49 PM
  4. integrating vlookup and cell functions
    By AMT in forum ExcelTip.com Feedback / Comments / Suggestions
    Replies: 3
    Last Post: 11-29-2007, 10:47 AM
  5. Integrating VBA with C/C++
    By gajendra.gupta in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-08-2007, 05:58 AM
  6. Integrating xls with vba
    By coder_arun in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-22-2006, 10:24 AM
  7. [SOLVED] Program VLookup
    By Steph in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-28-2006, 05:20 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