idea to create a 3rd table from other 2 tables

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
fHi
I have a file which has 2 sheets. The first sheet has table like this
student nonameemail
1smith, johnjohn.smith@hello.com
22clark,marymary.clark@hello.com

<tbody>
</tbody>


The second sheet has table like this

last namefirst namestudent Noclass codefull name
smithjohn1abc-123smith, john
smithjohn1xyz-111smith, john
smithjohn1aaa-120smith, john
clarkmary22abc-123clark,mary
clarkmary22hhh-000clark,mary

<tbody>
</tbody>

Now what I wan to do, is to create a 3rd sheet which is going to look like this

student nostudent nameemail addresscourses
1smith, johnjohn.smith@hello.comabc-123
1xyz-111
1aaa-123
22clark, marymary,clark@hello.comabc-123

<tbody>
</tbody>

Any idea how to create the 3rd table? I was thinking of Pivot table. I want a solution but not VBA as I am not familiar with it yet. Thanks a lot.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
=VLOOKUP("SMITH, JOHN",B2:C100,2,FALSE)

Replace Smith, John with the first cell reference where this list truly starts. Like B2 (in your example).

Replace B2:C100 with the range that encompasses both the names and email addresses.

Replace the 2 with whatever column the email addresses are in. The first column in this count is the first one in your range. In my example formula, Column B = 1 and Column C = 2.

This will pull in your email addresses for each name in your list. Drag down as far as needed.

False just makes the formula look for an exact match. Do not change this.
 
Upvote 0
Thanks for your reply. Where should I put this Vlookup() function? and why you are passing one name as an argument?

=VLOOKUP("SMITH, JOHN",B2:C100,2,FALSE)

Replace Smith, John with the first cell reference where this list truly starts. Like B2 (in your example).

Replace B2:C100 with the range that encompasses both the names and email addresses.

Replace the 2 with whatever column the email addresses are in. The first column in this count is the first one in your range. In my example formula, Column B = 1 and Column C = 2.

This will pull in your email addresses for each name in your list. Drag down as far as needed.

False just makes the formula look for an exact match. Do not change this.
 
Upvote 0
lezawang,

Here is a macro solution for you to consider.

You can change the worksheet names in the macro.

Sample raw data worksheets:


Excel 2007
ABC
1student nonameemail
21smith, johnjohn.smith@hello.com
322clark,marymary.clark@hello.com
4
Sheet1



Excel 2007
ABCDE
1last namefirst namestudent Noclass codefull name
2smithjohn1abc-123smith, john
3smithjohn1xyz-111smith, john
4smithjohn1aaa-120smith, john
5clarkmary22abc-123clark,mary
6clarkmary22hhh-000clark,mary
7
Sheet2


And, after the macro in a new worksheet:


Excel 2007
ABCD
1student nostudent nameemail addresscourses
21smith, johnjohn.smith@hello.comabc-123
31xyz-111
41aaa-120
522clark,marymary.clark@hello.comabc-123
622hhh-000
7
Sheet3


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 lezawang()
' hiker95, 01/28/2017, ME988082
Dim w1 As Worksheet, w2 As Worksheet, w3 As Worksheet
Dim lr As Long, r As Long, n As Long, sn As Range
Application.ScreenUpdating = False
Set w1 = Sheets("Sheet1")   '<-- you can change the sheet name here
Set w2 = Sheets("Sheet2")   '<-- you can change the sheet name here
If Not Evaluate("ISREF(Sheet3!A1)") Then Worksheets.Add(After:=w2).Name = "Sheet3"
Set w3 = Sheets("Sheet3")
w3.UsedRange.Clear
w3.Range("A1").Resize(, 4).Value = Array("student no", "student name", "email address", "courses")
With w2
  lr = .Cells(Rows.Count, 1).End(xlUp).Row
  w3.Range("A2").Resize(lr - 1).Value = .Range("C2:C" & lr).Value
  w3.Range("D2").Resize(lr - 1).Value = .Range("D2:D" & lr).Value
End With
With w3
  For r = 2 To lr
    n = Application.CountIf(.Columns(1), .Cells(r, 1).Value)
    Set sn = w1.Columns(1).Find(.Cells(r, 1).Value, LookAt:=xlWhole)
    If Not sn Is Nothing Then
      .Cells(r, 2).Resize(, 2).Value = w1.Cells(sn.Row, 2).Resize(, 2).Value
    End If
    r = r + n - 1
  Next r
  .Columns(1).Resize(, 4).AutoFit
  .Activate
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 lezawang macro.
 
Upvote 0

Forum statistics

Threads
1,215,460
Messages
6,124,949
Members
449,198
Latest member
MhammadishaqKhan

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