Consulting

Results 1 to 7 of 7

Thread: Solved: vba vlookup fix

  1. #1

    Solved: vba vlookup fix

    Hi all,
    pls. i have a code, but it doesnt works as i wish...
    This is only part of it, but here is something wrong..

    what i try to do with this code is - From active cell i want only value without last 3 character. This value, i try to search in sheet ALL in column C. Now it works, but nothing is found (but the value is in column C). By debuging it return that value found has error 2042.

    pls. can you help me?

    Dim cif, cif2
    Dim pval, pvall2 As String
    Dim i
    Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    Dim vysledok As String
    Dim found As Variant
    Dim Rng As Range
    Dim LookFor As Range
    Set Rng = Workbooks("file.xls").Sheets("ALL").Columns("C:D")
    vysledok = Left(ActiveCell.Value, Len(ActiveCell.Value) - 3)
    found = Application.VLookup(vysledok, Rng, 1, 0)
    If IsError(found) = False Then GoTo cisloU

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Is column C numbers, if so, cast vysledok to a number also.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    In column C is in rows 1 to 30 names and numbers (many diferent characters, header...). And from row 30 starts only numbers.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    And is your lookup on a number?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    yes, on number
    but when i define vysledok as integer it return "error Overflow"

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this

    [vba]

    Dim cif, cif2
    Dim pval, pvall2 As String
    Dim i
    Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    Dim vysledok As Variant
    Dim found As Variant
    Dim Rng As Range
    Dim LookFor As Range
    Set Rng = Workbooks("file.xls").Sheets("ALL").Columns("C")
    vysledok = Left(ActiveCell.Value, Len(ActiveCell.Value) - 3)
    If IsNumeric(vysledok) Then vysledok = CLng(vysledok)
    found = Application.VLookup(vysledok, Rng, 1, 0)
    If IsError(found) = False Then GoTo cisloU
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    yes it works perfectly
    thank you very much

Posting Permissions

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