Creating a list of dates

killar65

New Member
Joined
Jul 11, 2017
Messages
23
Hi guys,

Hopefully there is a simple solution to this problem.

I would like to create a list of dates in a column based on the results of the data in another column. So,

In col A i have a range of dates that are random dates from throughout the year.

In col B I have either a 1 or a 0...the 1 represents that a certain random event occurred on that date, whilst the 0 represents the event not occurring on that date.

I in col C I would like to create a list of dates of when the event occurred...ie...C1 first time the event occurred, C2, the next...etc.

Any help and guidance would be greatly appreciated.

James
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Is this what you mean?
Row #1 is a Header Row
Code:
Sub Maybe()
Dim c As Range
    For Each c In Range("B2:B" & Cells(Rows.Count, 2).End(xlUp).Row)
        If c.Value = 1 Then Cells(Cells(Rows.Count, 3).End(xlUp).Row, 3).Offset(1) = c.Offset(, -1)
    Next c
End Sub
For a large amount of Data, AutoFilter will be faster.
 
Upvote 0
Hi Jolivanes,

Many thanks for your prompt reply....please excuse my excel ignorance, but, how do i get this to work??

What do I place in the cells of the C col for the results to occur?

James
 
Upvote 0
Is this what you mean?
Row #1 is a Header Row
Code:
Sub Maybe()
Dim c As Range
    For Each c In Range("B2:B" & Cells(Rows.Count, 2).End(xlUp).Row)
        If c.Value = 1 Then Cells(Cells(Rows.Count, 3).End(xlUp).Row, 3).Offset(1) = c.Offset(, -1)
    Next c
End Sub
For a large amount of Data, AutoFilter will be faster.

@jolivanes, killar65...
The above macro can be written without using a loop...
Code:
[table="width: 500"]
[tr]
	[td]Sub Maybe()
  Dim LastRow As Long, Arr As Variant
  LastRow = Cells(Rows.Count, "B").End(xlUp).Row
  Arr = Split(Application.Trim(Join(Evaluate(Replace("TRANSPOSE(IF(B2:B#=1,A2:A#,""""))", "#", LastRow)))))
  Range("C2").Resize(1 + UBound(Arr)) = Application.Transpose(Arr)
End Sub[/td]
[/tr]
[/table]


@killar65,

HOW TO INSTALL MACROs
------------------------------------
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (Maybe) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.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.
 
Upvote 0
Code:
Sub Maybe_2()
Application.ScreenUpdating = False
With Sheets("Sheet1").Cells(1, 1).CurrentRegion
    .AutoFilter 2, 1
    .Cells(1, 1).CurrentRegion.Columns(1).Offset(1).Copy Cells(2, 3)
    .AutoFilter
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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