For each and If with worksheet function

justin 00089

New Member
Joined
Jun 24, 2019
Messages
10
Trying to find time gaps based off each cell and its offset (the next cell down) in a dynamic range. My error message right now is 'object required' in the if statement.

For Each cell In picks()
If WorksheetFunction.Abs(cell.Offset(-1, 0).Value - cell.Value) > 0.02083 Then

do something

ElseIf WorksheetFunction.Abs(cell.Offset(-1, 0).Value, -cell.Value) = cell.Value Then

do nothing

end if
Next Cell
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Can we see the test of your code to see how "pick()" is defined?
 
Upvote 0
it is actually meant to be numbers() but it is defined as a dynamic range as follows

l = Worksheets("Sheet1").Cells(Worksheets("Sheet1").Rows.Count, "C").End(xlUp).Row
Set numbers = Range("C2:C" & l)
 
Upvote 0
You shouldn't have "()" after picks or numbers, if it is just a range variable.
Also, confirm what the value of "l" is in a message box, to make sure it is some value greater than 1.
If it is 1, you are going to have issues with the cell.Offset(-1, 0) reference, as you cannot move up 1 row from the first row.

If those things do not solve your problem, please post the entire code for us to analyze.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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