Interview Question: Excel dataset scenario

01's

Board Regular
Joined
Jun 1, 2011
Messages
85
Hi,

I have an Excel database with around 1000 rows of data. Data are arranged as below with around 300 names and with multiple skills for each Name.

Name skill
Shrinivas Excel
Shrinivas VBA
Veer C++
Veer UID
Veer Analytics

I need output like below using excel function and VBA both separately. Thanks for your help!

Name skill1 skill2 skill3
Shrinivas Excel VBA
Veer C++ UID Analytics
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
01's,

With your raw data in in Columns A, and, B, the results will be written beginning in cell D1.

Try the following macro.

Code:
Sub ReroganizeData()
' hiker95, 08/24/2017, ME1020294
' Thank you MickG
Dim Dic As Object, Ray As Variant, k As Variant, G As Variant
Dim Rw As Long, Ac As Long, c As Long, a As Long, oMax As Long
Ray = Range("A2:B" & Range("A" & Rows.Count).End(xlUp).Row)
Set Dic = CreateObject("Scripting.Dictionary")
Dic.CompareMode = 1
For Rw = 1 To UBound(Ray, 1)
  For Ac = 2 To UBound(Ray, 2)
    If Not Dic.Exists(Ray(Rw, 1)) Then
      Set Dic(Ray(Rw, 1)) = CreateObject("Scripting.Dictionary")
    End If
    Dic(Ray(Rw, 1))(Ray(Rw, Ac)) = Empty
  Next Ac
Next Rw
ReDim nray(1 To UBound(Ray, 1), 1 To UBound(Ray, 1) * UBound(Ray, 2))
For Each k In Dic.Keys
  c = c + 1: a = 1
  nray(c, 1) = k
  For Each G In Dic(k)
    a = a + 1
    nray(c, a) = G
    oMax = Application.Max(oMax, a)
  Next G
Next k
Range("D1").Value = Range("A1").Value
With Range("D2").Resize(c, oMax)
  .Value = nray
  Columns(4).Resize(, oMax).AutoFit
End With
With Range("E1").Resize(, oMax - 1)
  .Formula = "=""skill"" & Column() - 4"
  .Value = .Value
End With
Columns.AutoFit
End Sub
 
Last edited:
Upvote 0
Works like a charm!!!
Thanks Hiker95 :)
The interviewer had asked me whether this is possible through Excel formulae and which one. Any idea on that?
01's,

With your raw data in in Columns A, and, B, the results will be written beginning in cell D1.

Try the following macro.

Code:
Sub ReroganizeData()
' hiker95, 08/24/2017, ME1020294
' Thank you MickG
Dim Dic As Object, Ray As Variant, k As Variant, G As Variant
Dim Rw As Long, Ac As Long, c As Long, a As Long, oMax As Long
Ray = Range("A2:B" & Range("A" & Rows.Count).End(xlUp).Row)
Set Dic = CreateObject("Scripting.Dictionary")
Dic.CompareMode = 1
For Rw = 1 To UBound(Ray, 1)
  For Ac = 2 To UBound(Ray, 2)
    If Not Dic.Exists(Ray(Rw, 1)) Then
      Set Dic(Ray(Rw, 1)) = CreateObject("Scripting.Dictionary")
    End If
    Dic(Ray(Rw, 1))(Ray(Rw, Ac)) = Empty
  Next Ac
Next Rw
ReDim nray(1 To UBound(Ray, 1), 1 To UBound(Ray, 1) * UBound(Ray, 2))
For Each k In Dic.Keys
  c = c + 1: a = 1
  nray(c, 1) = k
  For Each G In Dic(k)
    a = a + 1
    nray(c, a) = G
    oMax = Application.Max(oMax, a)
  Next G
Next k
Range("D1").Value = Range("A1").Value
With Range("D2").Resize(c, oMax)
  .Value = nray
  Columns(4).Resize(, oMax).AutoFit
End With
With Range("E1").Resize(, oMax - 1)
  .Formula = "=""skill"" & Column() - 4"
  .Value = .Value
End With
Columns.AutoFit
End Sub
 
Upvote 0
Morning,
Yes there is a formula that you can use.
You need to make the names Unique.
see example below.
NameskillSkill 1Skill 2Skill 3
ShrinivasExcelShrinivasExcelVBANo Skill
ShrinivasVBAVeerC++UIDAnalytics
VeerC++
VeerUID
VeerAnalytics

<colgroup><col width="64" span="7" style="width:48pt"> </colgroup><tbody>
</tbody>

The formula below.
Use SHFT+CTL+ENTER not just enter
Code:
{=IFERROR(INDEX($B$2:$B$6,SMALL(IF($D2=$A$2:$A$6,ROW($A$2:$A$6)-MIN(ROW($A$2:$A$6))+1,""),COLUMN(A1))),"No Skill")}
 
Upvote 0
Wow Great!!! Thanks DHayes. Another magic formula. Loved it.
Morning,
Yes there is a formula that you can use.
You need to make the names Unique.
see example below.
NameskillSkill 1Skill 2Skill 3
ShrinivasExcelShrinivasExcelVBANo Skill
ShrinivasVBAVeerC++UIDAnalytics
VeerC++
VeerUID
VeerAnalytics

<tbody>
</tbody>

The formula below.
Use SHFT+CTL+ENTER not just enter
Code:
{=IFERROR(INDEX($B$2:$B$6,SMALL(IF($D2=$A$2:$A$6,ROW($A$2:$A$6)-MIN(ROW($A$2:$A$6))+1,""),COLUMN(A1))),"No Skill")}
 
Upvote 0

Forum statistics

Threads
1,216,175
Messages
6,129,299
Members
449,499
Latest member
HockeyBoi

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