Help with Cycling through Ranges

oric

New Member
Joined
Jul 19, 2005
Messages
36
Hi all,

I wanted to get some peoples advice on how to write efficient code to work with cycling through 2 ranges. Here is my issue.

I have a whole bunch of experimental data. On sheet1 I have the times in which my events of interest happenned. So sheet1 looks something like

Column A Column B
eventID EventTime

On sheet 2 I have the times in which my detectors were turned on and off

Column A Column B Column C
DetectorID Time-on Time-off


What I would like to do is cycle through each event and check to see if any of the detectors were on when the event occured. If the detector was on then I would like to return the detector ID(s) in the columns next to my EventTime of sheet1.

This is the skeleton of my code so far.
Code:
Sub practice()
Dim Event As Range, DetectorTime As Range, EventRange As Range 
Dim DetectorRange As Range 
Set EventRange = Sheets(1).Range("B1:B" &  _ Range("B65536").End(xlUp).Row)
Set DetectorRange = Sheets(2).Range("B1:B" &  _ Range("B65536").End(xlUp).Row)
    For Each Event In EventRange
       For Each DetectorTime In DetectorRange
           If Event.Value >= DetectorTime.Value And Event.Value <= DetectorTime.Offset(0,1).Value Then
               Event.Offset(0, 1).Value = DetectorTime.Offset(0,-1).Value
           End If
       Next
    Next
End Sub

I have a lot of data (>5000 events and ~1000 detectors). I don't know if this is the most efficient way to go through these 2 ranges.

Thanks in advance..
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,214,909
Messages
6,122,189
Members
449,072
Latest member
DW Draft

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