+ Reply to Thread
Results 1 to 3 of 3

VBA Guidance needed

  1. #1
    Registered User
    Join Date
    11-01-2006
    Posts
    10

    VBA Guidance needed

    I don't know how to do this in VBA, this is the first time ive used it.

    I have a listbox on my UserForm that lists employees, the datasource is Sheet1!A5:A600. I want the user to be able to select a name, have the name populate a textbox, then the user can enter data in other txtBoxes and have that data populate cells in the same row as the name. This sounds very simple, but I just don't know.

    Here is what I've been able to cobble together so far.


    Private Sub lstBXEmployees_Click()

    Dim Employee As Variant
    Dim Name As String
    Dim Dept As String
    Dim DOB As String
    Dim manufac As String
    Dim lot As String
    Dim ExpDate As String
    Dim dateGiven As String
    Dim VacType As String
    Dim dose As String
    Dim route As String


    Employee = Empty
    'If you add more than 500 names you will need to increase this
    With ActiveSheet.Range("a5:a602")
    Name = lstBXEmployees.Value
    Set Employee = .Find(what:=Name, LookIn:=xlValues)


    'txtName.Text = Name
    If Not Employee Is Nothing Then Employee.Rows.EntireRow.Select
    txtName.Text = Name
    txtDOB.Text = DOB


    ' Exit Sub
    'End If

    End With
    'closes the form when you click on a name

    Set Employee = Nothing

    End Sub

    the Name is populating the txtName textbox, however I dont know how to populate the other textboxes. How do you tell what row to populate?

  2. #2
    Forum Contributor funkymonkUK's Avatar
    Join Date
    01-07-2005
    Location
    London, England
    Posts
    500
    Quote Originally Posted by hexOffender
    I don't know how to do this in VBA, this is the first time ive used it.

    I have a listbox on my UserForm that lists employees, the datasource is Sheet1!A5:A600. I want the user to be able to select a name, have the name populate a textbox, then the user can enter data in other txtBoxes and have that data populate cells in the same row as the name. This sounds very simple, but I just don't know.

    Here is what I've been able to cobble together so far.


    Private Sub lstBXEmployees_Click()

    Dim Employee As Variant
    Dim Name As String
    Dim Dept As String
    Dim DOB As String
    Dim manufac As String
    Dim lot As String
    Dim ExpDate As String
    Dim dateGiven As String
    Dim VacType As String
    Dim dose As String
    Dim route As String


    Employee = Empty
    'If you add more than 500 names you will need to increase this
    With ActiveSheet.Range("a5:a602")
    Name = lstBXEmployees.Value
    Set Employee = .Find(what:=Name, LookIn:=xlValues)


    'txtName.Text = Name
    If Not Employee Is Nothing Then Employee.Rows.EntireRow.Select
    txtName.Text = Name
    txtDOB.Text = DOB


    ' Exit Sub
    'End If

    End With
    'closes the form when you click on a name

    Set Employee = Nothing

    End Sub

    the Name is populating the txtName textbox, however I dont know how to populate the other textboxes. How do you tell what row to populate?
    Sorry I dont understand what you are trying to do. Do you have some screen shots or a sample xls file you could upload as a zip for us to work with?

    Are you trying to populate a lot of textboxs (Name, DOB, Gender, address , etc...) based on the name that the user has selected?

  3. #3
    Registered User
    Join Date
    11-01-2006
    Posts
    10
    I am trying to populate the cells in the row that the user has picked, based on the name in a listbox. Actually i figured it out... I just set the activecell.row to a string, and acticecell.column to a string then just do a
    worksheet.cells(row,cell+2 or cell+3 etc.)=txtbox.text . Somethings you just have to figure out yourself...but it's nice to have forums for thinking outloud with.
    Last edited by hexOffender; 11-01-2006 at 12:09 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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