MASWORLD
asked on
How to replace all number on Excel Sheet with text on same sheet
hi Experts
i have time attendance machine export the employment attendance report in Excel like this
Sheet 1
employee Time
1 08:00 AM 1-1-2015
1 16:00 PM 1-1-2015
2 08:01 AM 1-1-2015
2 16:00 PM 1-1-2015
3 08:00 AM 1-1-2015
3 16:00 PM 1-1-2015
While i have an excel sheet with employments names and number like that
Sheet 2
Employe Number Employe Name
1 michael
2 mas
3 edward
all i need to replace the number on sheet 1 to be the name on sheet 2 to be like this
Employee Time
michael 08:00 AM 1-1-2015
michael 16:00 PM 1-1-2015
mas 08:01 AM 1-1-2015
mas 16:00 PM 1-1-2015
edward 08:00 AM 1-1-2015
edward 16:00 PM 1-1-2015
i have time attendance machine export the employment attendance report in Excel like this
Sheet 1
employee Time
1 08:00 AM 1-1-2015
1 16:00 PM 1-1-2015
2 08:01 AM 1-1-2015
2 16:00 PM 1-1-2015
3 08:00 AM 1-1-2015
3 16:00 PM 1-1-2015
While i have an excel sheet with employments names and number like that
Sheet 2
Employe Number Employe Name
1 michael
2 mas
3 edward
all i need to replace the number on sheet 1 to be the name on sheet 2 to be like this
Employee Time
michael 08:00 AM 1-1-2015
michael 16:00 PM 1-1-2015
mas 08:01 AM 1-1-2015
mas 16:00 PM 1-1-2015
edward 08:00 AM 1-1-2015
edward 16:00 PM 1-1-2015
Or you can use this macro. It assumes that the names of the sheets are actually Sheet1 and Sheet2 and that the data on both sheets starts in column A.
My apologies if you already know how to add a macro but just in case...
In Excel, Press Alt+F11 to open Visual Basic Editor (VBE)
Right-click on your workbook name in the "Project-VBAProject" pane (at the top left corner of the editor window) and select Insert -> Module from the context menu
Copy the macro (you can use the ‘Select All’ button if you like) and paste it into the right-hand pane of the VBA editor ("Module1" window)
Press Alt+F11 again to go back to Excel
Optionally, press Alt+F8 to open the "Macro" dialog window. Select the macro, click ‘Options…’, hold down the Shift key and type the letter A (or any other letter) and click ‘OK’. Then anytime you want to run the macro press Ctrl+Shift+A
Sub NumbersToNames()
Dim wsNumbers As Worksheet
Dim wsNames As Worksheet
Dim lngLastRowNbrs As Long
Dim lngLastRowNames As Long
Dim lngRowNbrs As Long
Dim lngRowNames As Long
Set wsNumbers = Sheets("Sheet1")
Set wsNames = Sheets("Sheet2")
lngLastRowNbrs = wsNames.Range("A1048576").End(xlUp).Row
lngLastRowNames = wsNames.Range("A1048576").End(xlUp).Row
For lngRowNbrs = 2 To lngLastRowNbrs
For lngRowNames = 2 To lngLastRowNames
With wsNumbers
If .Cells(lngRowNbrs, "A") = wsNames.Cells(lngRowNames, "A") Then
.Cells(lngRowNbrs, "A") = wsNames.Cells(lngRowNames, "B")
End If
End With
Next
Next
End Sub
My apologies if you already know how to add a macro but just in case...
In Excel, Press Alt+F11 to open Visual Basic Editor (VBE)
Right-click on your workbook name in the "Project-VBAProject" pane (at the top left corner of the editor window) and select Insert -> Module from the context menu
Copy the macro (you can use the ‘Select All’ button if you like) and paste it into the right-hand pane of the VBA editor ("Module1" window)
Press Alt+F11 again to go back to Excel
Optionally, press Alt+F8 to open the "Macro" dialog window. Select the macro, click ‘Options…’, hold down the Shift key and type the letter A (or any other letter) and click ‘OK’. Then anytime you want to run the macro press Ctrl+Shift+A
Change line 13 in my post ID: 40846528 to
lngLastRowNbrs = wsNumbers.Range("A1048576" ).End(xlUp ).Row
Are the sheets named "Sheet1" and "Sheet2"?
Does the data on both sheets start in column "A"?
lngLastRowNbrs = wsNumbers.Range("A1048576"
Are the sheets named "Sheet1" and "Sheet2"?
Does the data on both sheets start in column "A"?
ASKER
Are the sheets named "Sheet1" and "Sheet2"?
yes sheet1 num sheet2 names
Does the data on both sheets start in column "A"?
yes num in column "A" in sheet1 name in column "A" in sheet2
yes sheet1 num sheet2 names
Does the data on both sheets start in column "A"?
yes num in column "A" in sheet1 name in column "A" in sheet2
Can you attach your workbook please?
ASKER
ok
21.xlsx
21.xlsx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks for help Excellent :)
You're welcome and I'm glad I was able to help.
In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015
In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015
you could use a helper's column and this formula and the copy and paste the value to right place
=VLOOKUP(A2,Sheet2!$A$2:$B
Regards