Using VBA or Macros to get multiple results

jarust91

New Member
Joined
Sep 21, 2017
Messages
8
Hello,

I currently have a table with a couple thousand pieces of data. What I am trying to do is create a formula of some type to know all the corresponding dates to a certain person based on their status.

NameStatusLast Modified
John DoeCompleted16-Aug
Jane DoeScheduled15-Aug
Jimmy DoeExited14-Aug
John DoeCompleted10-Aug
Jane DoeReg. Completed4-Aug
Jimmy DoeRegistration1-Aug
John DoeUnreachable31-Jul
Jane DoeCompleted31-Jul
Jimmy DoeScheduled29-Jul
John DoeReg. Completed25-Jul
Jane DoeAbandoned25-Jul
Jimmy DoeExited15-Jul
John DoeScheduled15-Jul
Jane DoeCompleted14-Jul
Jimmy DoeCompleted14-Jul
John DoeScheduled13-Jul
Jane DoeCompleted13-Jul
Jimmy DoeScheduled10-Jul

<colgroup><col><col><col></colgroup><tbody>
</tbody>

This is what the table looks like. I would want to know all the corresponding dates from John Doe when his status is completed. Ideally, I would be able to do this for all of the names.

Any help would be great appreciated.

Thanks,

Jarust91
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hello jarust91,

What would the output look like?
 
Upvote 0
Hello,

I would hope that the out put would look something like this:

<style><!--table {mso-displayed-decimal-separator:"\."; mso-displayed-thousand-separator:"\,";}@page {margin:.75in .7in .75in .7in; mso-header-margin:.3in; mso-footer-margin:.3in;}td {padding-top:1px; padding-right:1px; padding-left:1px; mso-ignore:padding; color:black; font-size:12.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:Calibri, sans-serif; mso-font-charset:0; mso-number-format:General; text-align:general; vertical-align:bottom; border:none; mso-background-source:auto; mso-pattern:auto; mso-protection:locked visible; white-space:nowrap; mso-rotate:0;}.xl63 {mso-number-format:"d\\-mmm";}--></style>
John Doe16-Aug10-Aug
Jane Doe31-Jul14-Jul13-Jul
Jimmy Doe14-Jul

<!--StartFragment--> <colgroup><col width="87" span="4" style="width:65pt"> </colgroup><tbody>
<!--EndFragment--></tbody>

So you would have the names, followed by all of the dates in corresponding columns.
 
Upvote 0
Hello,

I would hope that the out put would look something like this:

<style><!--table {mso-displayed-decimal-separator:"\."; mso-displayed-thousand-separator:"\,";}@page {margin:.75in .7in .75in .7in; mso-header-margin:.3in; mso-footer-margin:.3in;}td {padding-top:1px; padding-right:1px; padding-left:1px; mso-ignore:padding; color:black; font-size:12.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:Calibri, sans-serif; mso-font-charset:0; mso-number-format:General; text-align:general; vertical-align:bottom; border:none; mso-background-source:auto; mso-pattern:auto; mso-protection:locked visible; white-space:nowrap; mso-rotate:0;}.xl63 {mso-number-format:"d\\-mmm";}--></style>
John Doe16-Aug10-Aug
Jane Doe31-Jul14-Jul13-Jul
Jimmy Doe14-Jul

<tbody>
</tbody>

So you would have the names, followed by all of the dates in corresponding columns.

I have not found an easy way to get it into the format you have shown above. However, assuming 'name', 'status' & 'last modified' are in columns A, B & C respectively, the following macro will provide you with a list of completed status in columns E & F sorted by name then date (newest to oldest).

Code:
Sub Completed()
'
' Completed Macro
'


'
    Columns("E:F").Select
    Selection.ClearContents
    
    Range("A1").Select
    Selection.AutoFilter
    ActiveSheet.Range("A:C").AutoFilter Field:=2, Criteria1:="Completed"
    ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Clear
    ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Add Key:=Range _
        ("A:A"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Add Key:=Range _
        ("C:C"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.ActiveSheet.AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Copy
    Range("E1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("C1").Select
    Range(Selection, Selection.End(xlDown)).Copy
    Range("F1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    ActiveSheet.Range("A:C").AutoFilter Field:=2
    Application.CutCopyMode = False
    ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Clear
    ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Add Key:=Range _
        ("C:C"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.ActiveSheet.AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Selection.AutoFilter
    Range("E1").Select
End Sub
 
Upvote 0
@jarust91
Hi & welcome to the board.
Whilst you have asked for a formula.
Here is a macro that should do what you want, if you're interested.
This is based on your data being in cols A to C, with a header in row 1
Code:
Sub Fltr_Dict()


    Dim Cl As Range
    Dim Cnt As Long
    
    Columns(2).AutoFilter field:=1, Criteria1:="Completed"
    With CreateObject("scripting.dictionary")
        For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlVisible)
            If Not .exists(Cl.Value) Then
                .Add Cl.Value, Cl.Offset(, 2).Value
            Else
                .Item(Cl.Value) = .Item(Cl.Value) & "|" & Cl.Offset(, 2).Value
            End If
        Next Cl
        
        Columns(2).AutoFilter
        
        Range("E2").Resize(.Count).Value = Application.Transpose(.Keys)
        For Cnt = 0 To .Count - 1
            Range("F" & Cnt + 2).Resize(, UBound(Split(.Item(Range("E" & Cnt + 2).Value), "|")) + 1).Value _
                = Split(.Item(Range("E" & Cnt + 2).Value), "|")
        Next Cnt
    End With

End Sub
 
Upvote 0
Here is another macro for you to consider...
Code:
Sub Fltr_Dict()
  Dim R As Long, Status As String, Data As Variant
  Status = "Completed"
  Data = Range("A2", Cells(Rows.Count, "C").End(xlUp))
  With CreateObject("scripting.dictionary")
    For R = 1 To UBound(Data)
      If Data(R, 2) = Status Then .Item(Data(R, 1)) = .Item(Data(R, 1)) & Data(R, 3) & "|"
    Next
    Range("E2").Resize(.Count).Value = Application.Transpose(.Keys)
    Range("F2").Resize(.Count).Value = Application.Transpose(.Items)
  End With
  Columns("F").TextToColumns , xlDelimited, , , False, False, False, False, True, "|"
End Sub
 
Last edited:
Upvote 0
Thanks Fluff,

I tried running this macro, but got an error. It says: "Run-time error '429': ActiveX component can't create object". When I click debug it highlights this row: "With CreateObject("scripting.dictionary")".

I apologize, but I probably should have specified that I am running this on a MacBook using the latest version of Excel for Mac.
 
Upvote 0
As far as I know, the scripting.dictionary won't work on a Mac.
If no-one else comes up with a solution I'll have another look tomorrow
 
Last edited:
Upvote 0
I have no experience with Mac, but if Pivot Tables are available try it.

Status --> Report Filter
Name and LastModified --> Row labels


Status​
Completed​
Name​
Last Modified
Jane Doe​
13/jul​
14/jul​
31/jul​
Jimmy Doe​
14/jul​
John Doe​
10/ago​
16/ago​

<tbody>
</tbody>

Hope this helps

M.
 
Upvote 0
Thank you for this macro. It did the job for me. There is just one thing I was hoping to add to it. Is there a way so that it can also sort the "last modified" so that the oldest date for a certain person appears first.

Thanks so much.

Jarust91
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,665
Members
449,045
Latest member
Marcus05

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