Consulting

Results 1 to 4 of 4

Thread: Look up for a value in a worksheet and store it in a variable

  1. #1
    VBAX Newbie
    Joined
    Jan 2012
    Posts
    2
    Location

    Look up for a value in a worksheet and store it in a variable

    Hi ,

    i want to look up for a value which can be in a column range and store it in a variable for further use . How can i do it?
    thanks, Carlo

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    More detail is needed.

    What value is being sought?

    What do you want to do if it isn't in the column?

    "store it for further use":
    1) store it where? what future use?
    2) if we know the value at the beginning, why look in the column, why not just store it without looking?

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    If you just want to check if that value is there, try something like

    [vba]


    Dim cell As Range

    Set cell = Columns(1).Find("XYZ")
    If cell Is Nothing Then

    MsgBox "Not found"
    Else

    MsgBox "Found in row " & cell.Row
    End If
    [/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

  4. #4
    VBAX Newbie
    Joined
    Jan 2012
    Posts
    2
    Location
    first of all, thank you both
    then some clarifications for mikerikson :
    i want to store the result of the search in a variable as i need to verify whether that value has already been assigned in the cell 'x' of a specific row; this string value is already present in a cell of the row but has to be stored , given certain conditions , in the cell x to produce an encoding that will be used furthermore in another program .

    Since i'm trying to apply also other controls , by now i'm working on the first part of the development (very useful your post xld), than i'll be very glad if you could help me later on .
    Bye guys!

Posting Permissions

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