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 7500359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:09:16+00:00 2026-05-29T20:09:16+00:00

I have two excel spreadsheets, one contains data on various persons, while the other

  • 0

I have two excel spreadsheets, one contains data on various persons, while the other is more of an index.

The ‘Index’ spreadsheet is laid out as following (as an example);

      A       B
1 [person:][pID: ]
2 [Mark   ][1    ]
3 [James  ][2    ]
4 [John   ][3    ]
5 [David  ][4    ]
n [ ...   ][n    ]

The ‘Data’ spreadsheet is laid out as following (as an example);

      A
1 [pID:   ][ ...
2 [David  ][ ...
3 [David  ][ ...
4 [David  ][ ...
5 [James  ][ ...
6 [Mark   ][ ...
7 [David  ][ ...
n [ ...   ][ ...

What I would like to do is replace the column A in the ‘Data’ spreadsheet, with the corresponding index of the ‘Index’ spreadsheet, probably using VBA.

The result would be something like this;

      A
1 [pID:   ][ ...
2 [4      ][ ...
3 [4      ][ ...
4 [4      ][ ...
5 [2      ][ ...
6 [1      ][ ...
7 [4      ][ ...
n [ ...   ][ ...

I have seen some static approaches which use a switch statement, but I’d really like to be able to import the data from another spreadsheet.
I’m trying not to resort to copy pasting and ‘Replace All’.

Thanks!

  • 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-05-29T20:09:19+00:00Added an answer on May 29, 2026 at 8:09 pm

    Try this:

    Sub HTH()
    
        With Sheets("Data")
            .Columns(2).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
            .Cells(1, "B").Value = .Cells(1, "A").Value
            With .Range("A2", .Cells(Rows.Count, "A").End(xlUp)).Offset(, 1)
                .Formula = "=VLOOKUP(A2,Index!A:B,2,FALSE)"
                .Value = .Value
            End With
            .Columns(1).Delete
        End With
    
    End Sub
    

    Explanation:

    Sub HTH()
    
        With Sheets("Data")
            '// Insert a new column with same format
            .Columns(2).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
            '// Copy the header
            .Cells(1, "B").Value = .Cells(1, "A").Value
            '//  Work with the used range of column A 
            With .Range("A2", .Cells(Rows.Count, "A").End(xlUp)).Offset(, 1)
                '// Use a formula to replace the names with corresponding values
                .Formula = "=VLOOKUP(A2,Index!A:B,2,FALSE)"
                '// Replace formula with value
                .Value = .Value
            End With
            '//  Delete the old column
            .Columns(1).Delete
        End With
    
    End Sub
    

    NOTE:

    Personally, I would leave the Raw data sheet as is and use a presentation sheet which looks up the data sheet and the index sheet and presents it how you want it. Then you wont necessarily need code and if you still do want to use code then the code will be much simpler. You will need to add code to turn off screen updating and use error handling etc.

    An alternative to ja72’s solution:

    Sub HTH()
        Dim vNames As Variant, vResult As Variant
        Dim lLoop As Long
    
        vNames = Sheets("Index").UsedRange.Columns(1).Resize(, 2).Value2
        vResult = Sheets("Data").UsedRange.Columns(1).Value2
    
        With CreateObject("Scripting.Dictionary")
            For lLoop = 2 To UBound(vNames, 1)
                .Add vNames(lLoop, 1), vNames(lLoop, 2)
            Next lLoop
    
            For lLoop = 2 To UBound(vResult, 1)
                vResult(lLoop, 1) = .Item(vResult(lLoop, 1))
            Next lLoop
    
            Sheets("Data").Range("A1").Resize(UBound(vResult, 1), 1).Value = vResult
        End With
    
    End Sub
    

    quietly confident its faster too 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an excel spreadsheet with two columns, one with a list of exercises
I have a Excel spreadsheet that has two tabs, I have data on the
I have an Excel sheet with two column, one is a number , and
I'm using OleDb to select data from excel spreadsheets. Each spreadsheet can contain many
I have an excel spreadsheet with two columns. The first column is a label
Suppose i have the following raw data in excel spreadsheet: [Name ] [ID ]
I have two excel files. First excel file contains the Person Name and Total
I have two copies of an Excel 2010 spreadsheet, my copy for editing and
I have a growing set of Excel spreadsheets none with the same data structure.
I have two spreadsheets in Excel. Sheet1 is called Overview , and Sheet2 is

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.