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

  • Home
  • SEARCH
  • 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 6333049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:23:11+00:00 2026-05-24T18:23:11+00:00

Once again I’ve got a problem with mixed format data in excel file. I’ve

  • 0

Once again I’ve got a problem with mixed format data in excel file. I’ve got the file with column named “User Name”. The biggest problem for me to solve is that data in this column consists of last name and first name of person in totally mixed format. For example:

“User Name”
John Smith
Carter Mike
Garfield, Tom

And so on…

I’ve got the second file which contains data in the proper format, I’ve got there 3 columns: “Last Name”, “First Name” and “Id”. What I need to do is to copy the Id that match the person from the second file to the first file.

My idea was to loop through “User Name” column and compare it using InStr function with at first “Last Name” column and if it matches to compare with “First Name” column. Then if there is a match I would copy Id to the column “B” in the first file. But it turned out that I’m too weak in VBA.

Here is what I’ve written. It doesn’t work at all, but maybe will help you to understand what my problem is:

Option Explicit

Sub FindID()

Dim rLastCell, rFirstCell, rUserCell As Range
Dim LastCell, FirstCell, UserCell As Range
Dim file As Workbook
Dim i As Long

'open file to compare
Set file = Workbooks.Open(Filename:=ThisWorkbook.Path & "\gooddata.xls")

'set last used cell
Set rLastCell = file.Worksheets("Sheet1").Range("A65536").End(xlUp)
Set rFirstCell = file.Worksheets("Sheet1").Range("B65536").End(xlUp)
Set rUserCell = ThisWorkbook.Worksheets("Sheet1").Range("C65536").End(xlUp)

With ThisWorkbook.Sheets("Sheet1")

For Each UserCell In .Range("C2:C" & rUserCell.Row)
    For Each LastCell In file.Sheets("Sheet1").Range("A2:A" & rLastCell.Row)
        If InStr(0, UserCell.Value, LastCell.Value, vbTextCompare) <> 0 Then
            For Each FirstCell In file.Sheets("Sheet1").Range("B2:B" & rFirstCell.Row)
                If InStr(0, UserCell.Value, FirstCell.Value, vbTextCompare) <> 0 Then
                    'copy id from gooddata.xls to baddata.xls
                End If
            Next FirstCell
        End If
    Next LastCell
Next UserCell

End With

file.Close savechanges:=True
Set file = Nothing

End Sub

Thanks for any advice.

  • 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-24T18:23:13+00:00Added an answer on May 24, 2026 at 6:23 pm

    Given that:

    • It needs to run a limited amount of times
    • The source data is badly formatted which demands some proofreading of the result
    • There will likely be some cases that need to manually ‘corrected’

    My advice is to use excel itself more than VBA. Specifically the VLOOKUP() function.
    If you do there are 2 ways to go with this

    The first:

    • In the gooddata and a few new columns that concatenate lastname/firstname in the different formats that you expect “Firstname Lastname”, “Lastname, Firstname” etc
    • Then in the baddata sheet at columns with a VLOOKUP() to do a lookup for the different formats where the lookup value is the id
    • Now you get multiple columns with ids for matched formats and blanks for missed lookups that you can evaluate and correct where needed

    The second is to do it the other way around:

    • Add a firstname and a lastname column in your baddata excelsheet that you populate from the name column (requires lot of left/instr stuff)
    • Create one combined (consistently formatted) name column that you can do a vlookup for in gooddata

    If you make sure to create proper formula’s you could simply paste in new ‘bad data’ in the username column for subsequent datasets

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

Sidebar

Related Questions

once again, IE is proving to be the biggest pain in the world, on
once again I've got a question. Since I am using Google Web Toolkit (GWT)
I'm trying to get it once again. I got a JS var which looks
I have a problem once again where I cant find the source code because
Once again I've hit a brick wall when debugging my android application. This problem
Hell once again, I am wondering how do you go about adding data to
Once again, I have a problem for which I would like to shave off
once again conversion problem in Delphi. I've been through some other topics, that refer
Good day once again. I have a (seemingly) simple problem. I'm trying to display
Once again I have an IE problem. I have a dropdown menu with <LI>

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.