Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8236221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:04:33+00:00 2026-06-07T19:04:33+00:00

I want to take a name from a sheet (let’s say A2 in a

  • 0

I want to take a name from a sheet (let’s say A2 in a sheet called ‘Names’) and search for that same name in another worksheet (say A2 in ‘Jobs’). After that name is found in the other worksheet I want to copy the value from the cell right next to it (still in ‘Jobs’ but B2) and return it to a different cell (E2) in the first sheet (‘Names’). I ultimately want to loop though all of the values in A1 of ‘Names’ and fill in the whole sheet.

I have gotten this far:

Sub fixThis()
    Dim i As Long, j As Long, col1 As Long, col2 As Long, lastrow1 As Long, lastrow2 As Long
    Dim sheetOne As String
    Dim sheetTwo As String

    col1 = 5
    col2 = 1
    sheetOne = "Names"
    sheetTwo = "Job"
    lastrow1 = Cells(Rows.Count, col1).End(xlUp).Row
    lastrow2 = Cells(Rows.Count, col2).End(xlUp).Row

    For i = 2 To lastrow1
        For j = 2 To lastrow2

           If sheetOne.Cells(i, col1).Value = sheetTwo.Cells(j, col2).Value Then

                sheetOne.Cells(i, 6).Value = sheetTwo.Cells(j, 2).Value

           End If
        Next
    Next
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:04:34+00:00Added an answer on June 7, 2026 at 7:04 pm

    It’s okay if you store the sheet names as strings. but when you use them you need to use them to reference the sheet object like this: Sheets("Sheetname").Cells().Value
    Or you can use a variable like this:

    Dim strSheet1name as String
    strSheet1name = "Sheet1"
    
    Sheets(strSheet1name).Cells().Value
    

    Finally if you really want to you can declare your own sheet object like

    Dim ws as worksheets
    ws = Sheets("Sheet1")
    
    ws.Cells.value
    

    To keep all of your above code the same you need to try replacing

           If sheetOne.Cells(i, col1).Value = sheetTwo.Cells(j, col2).Value Then
    
                sheetOne.Cells(i, 6).Value = sheetTwo.Cells(j, 2).Value
    
           End If
    

    With

           If Sheets(sheetOne).Cells(i, col1).Value = Sheets(sheetTwo).Cells(j, col2).Value Then
    
                Sheets(sheetOne).Cells(i, 6).Value = Sheets(sheetTwo).Cells(j, 2).Value
    
           End If
    

    Then finally, if you’re working with multiple sheets, you need to ad dmore detail to these lines:

    lastrow1 = Cells(Rows.Count, col1).End(xlUp).Row
    lastrow2 = Cells(Rows.Count, col2).End(xlUp).Row
    

    And change them to something like:

    lastrow1 = Sheets(SheetOne).Cells(Sheets(SheetOne).Rows.Count, col1).End(xlUp).Row
    lastrow2 = Sheets(SheetTwo).Cells(Sheets(SheetTwo).Rows.Count, col2).End(xlUp).Row
    

    The final version would look something like this:

    Sub fixThis()
        Dim i As Long, j As Long, col1 As Long, col2 As Long, lastrow1 As Long, lastrow2 As Long
        Dim sheetOne As String
        Dim sheetTwo As String
    
        col1 = 5
        col2 = 1
        sheetOne = "Names"
        sheetTwo = "Job"
        lastrow1 = Sheets(sheetOne).Cells(Sheets(sheetOne).Rows.Count, col1).End(xlUp).Row
        lastrow2 = Sheets(sheetTwo).Cells(Sheets(sheetTwo).Rows.Count, col2).End(xlUp).Row
    
        For i = 2 To lastrow1
            For j = 2 To lastrow2
                If Sheets(sheetOne).Cells(i, col1).Value = Sheets(sheetTwo).Cells(j, col2).Value Then
                    Sheets(sheetOne).Cells(i, 6).Value = Sheets(sheetTwo).Cells(j, 2).Value
                End If
            Next j
        Next i
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get host name from and inner URL. how to take that.
i am retrieving information from an excel sheet, i want to take the information
I want to take person's name and their phone number from the end user
I want to take two value from user i.e name and location and then
I want to print an attribute value based on its name, take for example
I want to take a math expression that takes variables and print (assign to
I want to take multiple integer inputs in same line eg :- input -1
I want to take an array and use that array's values to populate an
i want to take an array and cut some of the keys from it
I want to take the values from this site for the country table in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.