You are here:

- Home
- Computing/Technology
- Business Software
- Excel
- Times of Intrsecting Events

Advertisement

Hi Jerry,

Can you help me for this?

In one set of Columns, you have Starting and Ending Dates & Times of events.

In another Set of Columns, you have the same as above.

Now I want out put in third set of columns. Which is -

intersecting Dates and Time of First two sets of Columns with their concatenated Names.

Hope you will help creating a Macro for this.

The Same example which is showed below, is also attached as an Image.

Here is Example -

(A) (B) (C)

Event-1 Time Start Time End

KL 05/01/2068 07:14 06/01/2068 07:14

AB 01/01/2068 07:13 02/01/2068 07:13

CD 02/01/2068 07:13 03/01/2068 07:13

IJ 05/01/2068 07:14 05/01/2068 07:14

EF 03/01/2068 07:13 04/01/2068 07:14

GH 04/01/2068 07:14 05/01/2068 07:14

(E) (F) (G)

Event 2 Time Start Time End

OP 31/12/2068 01:15 01/01/2068 00:41

WX 03/01/2068 23:26 04/01/2068 21:36

QR 01/01/2068 00:41 02/01/2068 01:15

UV 03/01/2068 00:41 03/01/2068 23:26

ST 02/01/2068 01:15 03/01/2068 00:41

OUTPUT - RESULT based on above two sets of columns should be as below.

(I) (J) (K)

Intersecting

Events Time Start Time End

AB-QR 01/01/2068 07:13 02/01/2068 01:15

AB-ST 02/01/2068 01:15 02/01/2068 07:13

CD-ST 02/01/2068 07:13 03/01/2068 00:41

CD-UV 03/01/2068 00:41 03/01/2068 07:13

EF-UV 03/01/2068 07:13 03/01/2068 23:26

….etc … …

So, as you see in the example,

I want to List out those Event names, concatenated with each other, along with their Starting and Ending date-times sorted,

which intersect each other.

Hope you will help.

Thanks

Assuming the data is in the columns as described and the titles are in I1:K1 for the output, this macro will give you the intersecting events.

Correction:

Sub IntersectioningEvents()

Dim Ev1RNG As Range, Ev2RNG As Range, Ev1 As Range, Ev2 As Range, NR As Long

Set Ev1RNG = Range("A2:A" & Rows.Count).SpecialCells(xlConstants)

Set Ev2RNG = Range("E2:E" & Rows.Count).SpecialCells(xlConstants)

Range("I:K").SpecialCells(xlConstants).Offset(1).ClearContents

NR = 2

For Each Ev1 In Ev1RNG

For Each Ev2 In Ev2RNG

If (Ev1.Offset(, 1) < Ev2.Offset(, 1) And Ev1.Offset(, 2) > Ev2.Offset(, 1)) Or _

(Ev2.Offset(, 1) < Ev1.Offset(, 1) And Ev2.Offset(, 2) > Ev1.Offset(, 1)) Then

Range("I" & NR).Value = Ev1.Value & "-" & Ev2.Value

Range("J" & NR).Value = Application.WorksheetFunction.Median(Ev1.Offset(, 1), Ev1.Offset(, 2), Ev2.Offset(, 1))

Range("K" & NR).Value = Application.WorksheetFunction.Median(Ev1.Offset(, 1), Ev1.Offset(, 2), Ev2.Offset(, 2))

NR = NR + 1

End If

Next Ev2

Next Ev1

End Sub

This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

Answers by Expert:

Excel Formulas, macros, automation. Microsoft Excel MVP - 2010. Code site with free code snippets and techniques: http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/files

Microsoft Excel MVP - 2010. I have my own extensive Excel help/code site: http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/files
=====================
I have been offering free assistance as an Excel aid on many web sites for many years:
(http://www.excelforum.com - JBeaucaire) ======== (http://www.askmehelpdesk.com/spreadsheets - JBeaucaire) ======= (http://www.mrexcel.com/forum - jbeaucaire)**Education/Credentials**

Bachelor's Degree from Azusa Pacific University in Mathematics and Music Composition**Awards and Honors**

Microsoft Excel MVP 2010