Results 1 to 5 of 5

Thread: For each and If with worksheet function
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Jun 2019
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question For each and If with worksheet function

    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

  2. #2
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,765
    Post Thanks / Like
    Mentioned
    57 Post(s)
    Tagged
    11 Thread(s)

    Default Re: For each and If with worksheet function

    Can we see the test of your code to see how "pick()" is defined?
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

  3. #3
    New Member
    Join Date
    Jun 2019
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: For each and If with worksheet function

    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)

  4. #4
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,765
    Post Thanks / Like
    Mentioned
    57 Post(s)
    Tagged
    11 Thread(s)

    Default Re: For each and If with worksheet function

    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.
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

  5. #5
    New Member
    Join Date
    Jun 2019
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: For each and If with worksheet function

    will remove "()". one of those 2+2=5 moments.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •