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
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,974
Office Version
  1. 365
Platform
  1. Windows
Can we see the test of your code to see how "pick()" is defined?
 

justin 00089

New Member
Joined
Jun 24, 2019
Messages
10
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)
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,974
Office Version
  1. 365
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,312
Messages
5,600,887
Members
414,414
Latest member
neil_c

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
Top