locked
Copy Data From Worksheet to Worksheet RRS feed

  • Question

  • I have a employeeSpreadsheet that on EmployeeInfo holds the employeename in A3(Joe Marx) and in B3 employeeTitle and in C3 length of time in this position (numeric value).

    I need VBA to match on EmployeeName & employee Title and pull over the time in position.  Now the catch is (let's keep using me for example) Joe Marx could have 4 different employee titles as I could have worked 4 different positions.  I would need to pull back each individual position & length in the position.

    Friday, February 7, 2014 8:35 PM

All replies

  • Hi,

    I just wrote a sample to fetch the data as requested by you. Please find the code below:

    Sub dec()

    Dim name As String
    Dim position As String
    Dim exname As String
    Dim expos As String


    Dim rowcount As Integer

    name = inputbox("Enetr Name:", name)
    position = inputbox("Enter position :", Postion)

    rowcount = Sheet1.UsedRange.Rows.Count

    For i = 1 To rowcount
       
        exname = Sheet1.Cells(i + 2, 1)
        expos = Sheet1.Cells(i + 2, 2)
        If (exname = name And position = expos) Then
            MsgBox Sheet1.Cells(i + 2, 3)
            Exit For
        End If
    Next

    End Sub

    Please let me know, if this is what you required.

    Note: You need to fill the data in excel sheet as you mentioned above. ie in A3(Name), B3(Position) and C3(Number). You can fill any number of rows you want.

    Regards,

    Santhosh N

    Friday, February 7, 2014 9:26 PM
  • Hi,

    I just wrote a sample to fetch the data as requested by you. Please find the code below:

    Sub dec()

    Dim name As String
    Dim position As String
    Dim exname As String
    Dim expos As String


    Dim rowcount As Integer

    name = inputbox("Enetr Name:", name)
    position = inputbox("Enter position :", Postion)

    rowcount = Sheet1.UsedRange.Rows.Count

    For i = 1 To rowcount
       
        exname = Sheet1.Cells(i + 2, 1)
        expos = Sheet1.Cells(i + 2, 2)
        If (exname = name And position = expos) Then
            MsgBox Sheet1.Cells(i + 2, 3)
            Exit For
        End If
    Next

    End Sub

    Please let me know, if this is what you required.

    Note: You need to fill the data in excel sheet as you mentioned above. ie in A3(Name), B3(Position) and C3(Number). You can fill any number of rows you want.

    Regards,

    Santhosh N


    Is there a way to do this without requiring the user to input name & position?  The less room for human error the BETTER!
    Friday, February 7, 2014 9:37 PM