Consulting

Results 1 to 4 of 4

Thread: VBA - function Vlookup

  1. #1
    VBAX Regular
    Joined
    Nov 2022
    Posts
    13
    Location

    VBA - function Vlookup

    Hi everyone,
    In my module i pretend search a value corresponding to a variable a.
    But when i run the code variable h are incorrect, because apeear error 2042 and the suppose is appear a number.

    My code is:

    Sub Macro3()
    Dim j As Variant
    Dim a As Variant
    Dim h As Variant 'variavel de teste
    Set Model = Workbooks("AtrasosTotal.xlsm").Worksheets("Model")
    lastRowZModel = Model.Cells(Model.Rows.Count, "A").End(xlUp).Row
    a = 1600104092
    Sheets("Model").Select
    Set b = Range("A2:O" & lastRowZModel)
    h = Application.VLookup(a, b, 12, False)
    End Sub

    How can I resolve this problem
    Last edited by Aussiebear; 11-02-2022 at 03:01 AM. Reason: Added code tags to supplied code

  2. #2
    Wrap VBA code in Code tags !

    Sub M_snb()
       sn=Workbooks("AtrasosTotal.xlsm").sheets("Model").usedrange
    
       for j=1 to ubound(sn)
         if sn(j,1)=1600104092 then exit for
       next
    
       msgbox sn(j,12)
    End sub

  3. #3
    google error 2042.
    What is the reason for VBA error 2042? - Quora

    add an error handler to your code.

  4. #4
    VBAX Regular
    Joined
    Nov 2022
    Posts
    13
    Location
    Nice! It's working, but isn't efficient, because i have many lines for execute the cicle FOR.
    You have any sugestion?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •