0

What i'd like is that i can put in a excel formula a check to all parameters like this code below. The code runs without error if put it in a loop, but its slow and i have a small data-set (around 1500 records). what i have similar to this is a code that put "formula.local" values on a predefine table (so it auto-completes).

Bottom line i really need this code to runs faster... If there is a way to put it like a "local.formula", or even improve the code itself to run faster please let me know. If this is not clear please tell me and i'll try to explain better. Thanks.

If comp = "AC" Then
Cells(i, 77).Value = "AC"
GoTo nextrec
End If
If state = "idle" Then
    If resp >= obj Then
        'idle but already miss deadline
        Cells(i, 77).Value = "idle miss"
    Else
    'idle but ok 
        Cells(i, 77).Value = "idle"
    End If
Else
'ended
    If resp >= obj Then
        'ended miss deadline
        Cells(i, 77).Value = "ended missed"
    Else
        'deadline ok 
        Cells(i, 77).Value = "ended ok"
    End If
End If
6
  • Why not just use IF in formula? Commented Jan 9, 2019 at 12:24
  • Also, no need for the End If way of doing it, it's just if....else... like the 2nd part Commented Jan 9, 2019 at 12:30
  • 1
    Your code is incomplete. We cannot help on just a snippet of your code. What is state, resp, obj? Where is nextrec? Commented Jan 9, 2019 at 14:17
  • @Nathan_Sav my problem is that i cant build the if formula to check all those settings, allways something missing Commented Jan 9, 2019 at 14:52
  • i tryed to simplify the best i can .. fields status1 - can be "idle" or "processing"::: status2 - can be "missed" or "ok"::::: finally i need to add a column to have the values "idle but missed" "; idle ok" ; "ended missed"; "ended ok " Commented Jan 9, 2019 at 15:15

2 Answers 2

1

This can be done with a single excel formula without the need for VBA. The following formula should accomplish what your code does.

Since you didn't provide a snip of sample data I'm going to assume that comp, state, resp, obj are values from other columns of the same row. You can replace these values in my formula with the corresponding cell reference then drag down.

=IF(comp="AC",
    "AC",
    IF(state="idle",
          IF(resp>=obj,"idle miss","idle"),
          IF(resp>=obj,"ended miss","ended ok")
      )
    )
Sign up to request clarification or add additional context in comments.

Comments

0

@DavidN spot on , it is exactly how i need it ...for some reason i was not handling the multiple if statement the right way , i googled some examples but i just got even more messed up. has always the right way is the simple way. thanks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.