Forum Discussion
John_Maron
May 12, 2023Copper Contributor
Excel dunce! Please help! Don't even know what I'm trying to do is called!
I have a very basic understanding of Excel and need an answer to a question in the clearest terms possible. Step-by-step if possible. Or at least direction in what the function I am trying to accompl...
John_Maron
May 12, 2023Copper Contributor
Oh, and just so everyone knows, I totally made up the names, companies and email addresses I used in my examples. I know not to violate anyone's privacy.
OliverScheurich
May 13, 2023Gold Contributor
Sub transform()
Dim h, i, j, k, l, m As Long
Range("D2:G1048576").Clear
j = 2
k = 2
l = 2
m = 2
h = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To h
Select Case Cells(i, 1).Value
Case Is = "first name"
Cells(j, 4).Value = Cells(i, 2).Value
j = j + 1
Case Is = "last name"
Cells(k, 5).Value = Cells(i, 2).Value
k = k + 1
Case Is = "birthday"
Cells(l, 6).Value = Cells(i, 2).Value
l = l + 1
Case Is = "email"
Cells(m, 7).Value = Cells(i, 2).Value
m = m + 1
End Select
Next i
End SubAnother alternative could be these lines of code. In the attached file you can click the button in cell I2 to run the macro.