Consulting

Results 1 to 4 of 4

Thread: locating cells

  1. #1
    VBAX Tutor
    Joined
    Dec 2008
    Posts
    244
    Location

    locating cells

    I have a userform where the date is auto populated in a textbox. A combobox where the list is coming from Row A. and i also have a textbox where user will input a number.

    On my excel file, i have the date going acrross in the colum and the name going down the rows.

    A B C D E
    12/16/08 12/17/08 12/18/08 12/19/08 .......
    1. John
    2. Smith
    3. Joe
    4. Mark

    My question is, if on 12/16/08, i select Smith and input 2, how can I make it so that the result bill in cell("B2")?

    Thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim nRow As Long
    Dim nColumn As Long

    nRow = Application.Match(CLng(CDate(Me.ComboBox1.Value)), Rows("1:1"), 0)
    nColumn = Application.Match(Me.TextBox1.Value, Columns("A"), 0)
    Cells(nRow, nColumn).Value = TextBox2.Text
    [/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

  3. #3
    VBAX Tutor
    Joined
    Dec 2008
    Posts
    244
    Location
    [vba]
    nColumn = Application.Match(CLng(CDate(Me.txtdate.Value)), Rows("1:1"), 0)
    nRow = Application.Match(Me.combobox1.Value, Columns("A"), 0)
    Cells(nRow, nColumn).Value = UserForm1.textmissing.Text
    [/vba]

    Thanks xld, I follow through it and understand most of it, can I ask you what the why we need the CLng(Cdate?

    also, what is the "0" toward the end do?

    Thanks a lot xld

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The Cdate is required to cast the string date to a real date, the Clng casts that date to a number, which is how Excel stores date.

    The ,0 says to math on unsorted data, an exact match.
    ____________________________________________
    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

Posting Permissions

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