Matching Data from One Column to Another and Deleting Extra Rows

FrenchCelt

Board Regular
Joined
May 22, 2018
Messages
214
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm trying to finish up a macro by taking data (system username) from Column A and aligning it with the first entry in another column to contain that data to make a report easier to read.

This is what it looks like now:

1622405959462.png


And this is how I want it to look:

1622405922683.png


Basically I want the username from Column A to match up with the first entry for that name in Column B and then delete the subsequent entries, because the only one that matters is the earliest date in the sequence for each person.

Can anyone help me out?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.

Using XL2BB will generally get you faster and better answers as many helpers will just bypass your question rather than manually type out data to test with. ;)

Try this with a copy of your data.

VBA Code:
Sub MatchFirstRow()
  Dim Emp As Variant, EmpName As Variant
  Dim ErrRng As Range, NameFound As Range
  
  Emp = Range("A2", Range("A" & Rows.Count).End(xlUp)).Value2
  Range("A2", Range("A" & Rows.Count).End(xlUp)).ClearContents
  Set ErrRng = Range("B1", Range("B" & Rows.Count).End(xlUp))
  For Each EmpName In Emp
    Set NameFound = ErrRng.Find(What:="*:" & EmpName & " *")
    If Not NameFound Is Nothing Then NameFound.Offset(, -1).Value = EmpName
  Next EmpName
  ErrRng.Offset(, -1).SpecialCells(xlBlanks).EntireRow.Delete
End Sub
 
Upvote 0
Solution
Brilliant, that worked perfectly.

I would use that XL2BB add-in, but I post these at work and I never received permission from my IT Analyst to install it. I'll send another request.
 
Upvote 0
Brilliant, that worked perfectly.
You're welcome. Glad to help. :)

I would use that XL2BB add-in, but I post these at work and I never received permission from my IT Analyst to install it. I'll send another request.
If your request is denied, second best option because we can still manage to copy is a direct Copy/Paste like this

EmpError
Emp1Stuff :Emp1 and more 1
Emp2Stuff :Emp1 and more 2
Emp3Stuff :Emp1 and more 3
Stuff :Emp1 and more 4
Stuff :Emp1 and more 5
Stuff :Emp1 and more 6
Other Stuff :Emp2 and more 1
Yet more Stuff :Emp3 and more 1
Yet more Stuff :Emp3 and more 2
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top