grover1973

New Member
Joined
Jun 11, 2015
Messages
5
I need a vba for the below:

I have user names in one column and dates in another, user names repeat. This is dynamic list and user names might keep increasing

John 11/27/2014
Ash 11/28/2014
John 11/28/2014
Joey 12/01/2014
John 11/29/2014
Ash 12/15/2914

i want to change the table as below
John 11/27/2014 11/28/2014 11/29/2014
Ash 11/28/2014 12/15/2914
Joey 12/01/2014


Thanks for your help
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
This assumes your data are arranged in cols A & B as shown below. The data are reconfigured starting in D1.
<b>Sheet1</b><br /><br /><table border="1" cellspacing="0" cellpadding="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; padding-left:2pt; padding-right:2pt; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:64px;" /><col style="width:75px;" /><col style="width:64px;" /><col style="width:44px;" /><col style="width:225px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >A</td><td >B</td><td >C</td><td >D</td><td >E</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >1</td><td >Name</td><td >Date</td><td > </td><td >Name</td><td >Date(s)</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >2</td><td >John</td><td style="text-align:right; ">11/27/2014</td><td > </td><td >John</td><td > 11/27/2014 11/28/2014 11/29/2014</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >3</td><td >Ash</td><td style="text-align:right; ">11/28/2014</td><td > </td><td >Ash</td><td > 11/28/2014 12/15/2914</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >4</td><td >John</td><td style="text-align:right; ">11/28/2014</td><td > </td><td >Joey</td><td style="text-align:right; "> 12/1/2014</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td >Joey</td><td style="text-align:right; ">12/1/2014</td><td > </td><td > </td><td > </td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td >John</td><td style="text-align:right; ">11/29/2014</td><td > </td><td > </td><td > </td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7</td><td >Ash</td><td style="text-align:right; ">12/15/2914</td><td > </td><td > </td><td > </td></tr></table> <br /><br /><span style="font-family:Arial; font-size:9pt; font-weight:bold;background-color:#ffffff; color:#000000; ">Excel tables to the web >> </span><a style ="font-family:Arial; font-size:9pt; color:#fcf507; background-color:#800040; font-weight:bold;" href="http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4 </a>

Code:
Sub grover()
Dim R As Range, Vin As Variant, i As Long, j As Long, Dts As String
Set R = Range("A1:B" & Cells(Rows.Count, "B").End(xlUp).Row)
Vin = R.Value
Application.ScreenUpdating = False
R.Columns(1).AdvancedFilter Action:=xlFilterCopy, copytorange:=Range("D1"), unique:=True
Range("E1").Value = "Date(s)"
For i = 2 To Range("D" & Rows.Count).End(xlUp).Row
       For j = 2 To UBound(Vin, 1)
              If Range("D" & i).Value = Vin(j, 1) Then Dts = Dts & " " & Vin(j, 2)
       Next j
       Range("E" & i).Value = Dts
       Dts = ""
Next i
Columns("D:E").AutoFit
Application.ScreenUpdating = True
End Sub
 
Upvote 0
This assumes your data are arranged in cols A & B as shown below. The data are reconfigured starting in D1.
Sheet1

*ABCDE
1NameDate*NameDate(s)
2John11/27/2014*John 11/27/2014 11/28/2014 11/29/2014
3Ash11/28/2014*Ash 11/28/2014 12/15/2914
4John11/28/2014*Joey 12/1/2014
5Joey12/1/2014***
6John11/29/2014***
7Ash12/15/2914***

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:64px;"><col style="width:75px;"><col style="width:64px;"><col style="width:44px;"><col style="width:225px;"></colgroup><tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4

Code:
Sub grover()
Dim R As Range, Vin As Variant, i As Long, j As Long, Dts As String
Set R = Range("A1:B" & Cells(Rows.Count, "B").End(xlUp).Row)
Vin = R.Value
Application.ScreenUpdating = False
R.Columns(1).AdvancedFilter Action:=xlFilterCopy, copytorange:=Range("D1"), unique:=True
Range("E1").Value = "Date(s)"
For i = 2 To Range("D" & Rows.Count).End(xlUp).Row
       For j = 2 To UBound(Vin, 1)
              If Range("D" & i).Value = Vin(j, 1) Then Dts = Dts & " " & Vin(j, 2)
       Next j
       Range("E" & i).Value = Dts
       Dts = ""
Next i
Columns("D:E").AutoFit
Application.ScreenUpdating = True
End Sub

Thanks JoeMo.......I actually needed the dates in different columns not in one.
Your help is greatly appreciated
 
Upvote 0
Thanks JoeMo.......I actually needed the dates in different columns not in one.
Your help is greatly appreciated


Joe...........It did not take long for you to get the first VBA done, I am pretty sure the minor adjustment that i need will be a piece of cake for you. I wish i knew how to write macros.

I am thankful to you to helping me out.

Hope you can come up with changes. (One date in one column, next date in next column)

Regards,
 
Upvote 0
Thanks JoeMo.......I actually needed the dates in different columns not in one.
Your help is greatly appreciated
That's the kind of information that should be included in your OP - saves time for both of us.

Here's a revision:
Code:
Sub grover()
Dim R As Range, Vin As Variant, i As Long, j As Long, Dts As String, k As Long
Set R = Range("A1:B" & Cells(Rows.Count, "B").End(xlUp).Row)
Vin = R.Value
Application.ScreenUpdating = False
R.Columns(1).AdvancedFilter Action:=xlFilterCopy, copytorange:=Range("D1"), unique:=True
Range("E1").Value = "Date(s)"
For i = 2 To Range("D" & Rows.Count).End(xlUp).Row
       For j = 2 To UBound(Vin, 1)
              If Range("D" & i).Value = Vin(j, 1) Then Dts = Dts & " " & Vin(j, 2)
       Next j
       For k = LBound(Split(Dts, " ")) To UBound(Split(Dts, " ")) - 1
        Range("E" & i).Offset(0, k).Value = Split(Dts, " ")(k + 1)
    Next k
       Dts = ""
Next i
Range("D1").CurrentRegion.EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub
 
Upvote 0
That's the kind of information that should be included in your OP - saves time for both of us.

Here's a revision:
Code:
Sub grover()
Dim R As Range, Vin As Variant, i As Long, j As Long, Dts As String, k As Long
Set R = Range("A1:B" & Cells(Rows.Count, "B").End(xlUp).Row)
Vin = R.Value
Application.ScreenUpdating = False
R.Columns(1).AdvancedFilter Action:=xlFilterCopy, copytorange:=Range("D1"), unique:=True
Range("E1").Value = "Date(s)"
For i = 2 To Range("D" & Rows.Count).End(xlUp).Row
       For j = 2 To UBound(Vin, 1)
              If Range("D" & i).Value = Vin(j, 1) Then Dts = Dts & " " & Vin(j, 2)
       Next j
       For k = LBound(Split(Dts, " ")) To UBound(Split(Dts, " ")) - 1
        Range("E" & i).Offset(0, k).Value = Split(Dts, " ")(k + 1)
    Next k
       Dts = ""
Next i
Range("D1").CurrentRegion.EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub


My apologies, i should have mentioned it initially.

Many thanks for helping me out, appreciate it!
 
Upvote 0
You are welcome - thanks for the reply.

Joe...........Sorry but a change just came up and I was thinking if you can help me please.

Your VBA worked perfect but I am now required to arranbge that based on Months.
This is how it is now
Employee</SPAN>Date(s)</SPAN>Date(s)</SPAN>Date(s)</SPAN>Date(s)</SPAN>Date(s)</SPAN>Date(s)</SPAN>Date(s)</SPAN>Date(s)</SPAN>Date(s)</SPAN>Date(s)</SPAN>Date(s)</SPAN>Date(s)</SPAN>Absence</SPAN>Occurrence</SPAN>
John</SPAN>11/27/2014</SPAN>11/28/2014</SPAN>3/16/2015</SPAN>3/17/2015</SPAN>3/18/2015</SPAN> 2</SPAN>5</SPAN>
Joey</SPAN>11/12/2014</SPAN>11/13/2014</SPAN>12/24/2014</SPAN>5/25/2015</SPAN> 3</SPAN>4</SPAN>
William</SPAN>11/14/2014</SPAN>2/2/2015</SPAN> 2</SPAN>2</SPAN>
David</SPAN>11/28/2014</SPAN>1/30/2015</SPAN> 2</SPAN>2</SPAN>
Angela</SPAN>11/19/2014</SPAN>2/23/2015</SPAN>3/18/2015</SPAN>3/27/2015</SPAN> 4</SPAN>4</SPAN>
Eva</SPAN>11/17/2014</SPAN>11/18/2014</SPAN>12/29/2014</SPAN>12/30/2014</SPAN>1/2/2015</SPAN> 3</SPAN>5</SPAN>
John</SPAN>11/21/2014</SPAN>12/1/2014</SPAN>1/13/2015</SPAN>1/14/2015</SPAN> 3</SPAN>4</SPAN>
Joey</SPAN>11/3/2014</SPAN>11/4/2014</SPAN>1/30/2015</SPAN>3/6/2015</SPAN>4/8/2015</SPAN>5/1/2015</SPAN> 5</SPAN>6</SPAN>
William</SPAN>11/5/2014</SPAN>1/14/2015</SPAN>2/3/2015</SPAN>4/6/2015</SPAN>4/7/2015</SPAN>5/22/2015</SPAN> 5</SPAN>6</SPAN>
David</SPAN>11/17/2014</SPAN>11/18/2014</SPAN>11/19/2014</SPAN>11/20/2014</SPAN>1/12/2015</SPAN>3/2/2015</SPAN>3/3/2015</SPAN>3/9/2015</SPAN>3/10/2015</SPAN>3/11/2015</SPAN> 4</SPAN>10</SPAN>

<TBODY>
</TBODY><COLGROUP><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL></COLGROUP>


What I need is the absences and Occurences based on Months

If you can please help me here?

Regards,
 
Last edited:
Upvote 0

Forum statistics

Threads
1,203,047
Messages
6,053,195
Members
444,645
Latest member
mee siam

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