How to arrange data accordingly from different excel worksheet?

azrul94

New Member
Joined
Sep 7, 2017
Messages
1
Dear all,
Sorry for asking this question because I'm very new in understanding excel and I'm not a computer expertise.
I was given a task which contains about 20 thousands of data and have to arrange it accordingly to its ID.
I'm not very good at the words in excel so much, so I here i attach the example of what I have to do.
PjIcZv7


Excel 1
AB
1IDFUNCTION
2S1
3S2
4S6
5S10
6S10
7S20
8S21
9S22
10S22
11S23

<tbody>
</tbody>

Excel 2
ABC
1IDNAMEFUNCTION
2S1SAMSLEEP
3S2LILYWALK
4S3SIMSPEAK
5S5ROBERTRUN
6S7WILLIAMSWIM
7S10BETTYEAT
8S11ANNACYCLING
9S12DANNYANGRY
10S23DORYSAD

<tbody>
</tbody>

As you can see, the data that i need to transfer and arrange accordingly from Excel 2 to Excel 1 is the FUNCTION. But not all ID in Excel 1 is in Excel 2, same goes to not all ID in Excel 2 is in Excel 1. In Excel 1 the ID can be redundant, example: A5 with A6 and A9 with A10. Moreover, NAME are not required in Excel 1.

The result that I should get by transferring and arranging the data are as follows:
PjIcZv7


Excel 1
AB
1IDFUNCTION
2S1SLEEP
3S2WALK
4S6NA
5S10EAT
6S10
7S20NA
8S21NA
9S22NA
10S22
11S23SAD

<tbody>
</tbody>

The NA stands for not available. When the data comes to the redundant there will be blank space as example: A6 and A10. My data came in bulk that already consume my time for copy and paste one-by-one. If anyone could help me to sort this out by using any formula or anything? Im sorry for troubling you guys. If there is already thread like this can you guys link it?
Thank you so much.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
azrul94,

Welcome to the MrExcel forum.

Here is a macro solution for you to consider that is based on your three flat text displays.


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub azrul94()
' hiker95, 09/08/2017, ME1021885
Application.ScreenUpdating = False
Dim w1 As Worksheet, w2 As Worksheet
Dim r As Range, a As Range, rng As Range, n As Long
Set w1 = Sheets("Excel 1")
Set w2 = Sheets("Excel 2")
With w1
  For Each r In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
    Set rng = .Range("A2:A" & r.Row)
    n = Application.CountIf(rng, r)
    If n > 1 Then
      'do nothing
      GoTo Continue
    Else
      Set a = w2.Columns(1).Find(r.Value, LookAt:=xlWhole)
      If a Is Nothing Then
        r.Offset(, 1) = "NA"
      ElseIf Not a Is Nothing Then
        r.Offset(, 1).Value = a.Offset(, 2).Value
      End If
    End If
Continue:
  Next r
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the azrul94 macro.
 
Upvote 0

Forum statistics

Threads
1,217,284
Messages
6,135,642
Members
449,953
Latest member
Maniac189

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