logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

Adding Multiple Conditions to an Excel VBA IF Statement for Cells F6, H6

karolczyzycki 16368 5
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 7018505
    karolczyzycki
    Level 20  
    Posts: 581
    Rate: 43
    Hello.
    How in such an IF loop, add a few more conditions?
    At this point, error is shown if cell F6 is empty.
    How do I add a few more cells to this condition?
    my code:
    
    If (Range("F6") = "") Then
    Range("N6") = "Błąd"
    Else
    ..........
    end if

    This doesn't work:
    If (Range("F6,H6") = "") Then

    nor this:
    If (Range("F6" & "H6") = "") Then

    If it adds cells after the decimal point, it only satisfies the first condition, if I type "&" I get an error.
    What should I type in to make this work as a product of terms?
  • ADVERTISEMENT
  • #2 7018610
    Czybyszew
    Level 20  
    Posts: 275
    Help: 37
    Rate: 137
    If (Range("F6") = "") and (Range("H6") = "") and (Range("J6") = "") Then .....
  • ADVERTISEMENT
  • #3 7018651
    karolczyzycki
    Level 20  
    Posts: 581
    Rate: 43
    This code also throws an error:
    Quote:
    Run-time error '13':
    Type mismatch
  • ADVERTISEMENT
  • #4 7018706
    Czybyszew
    Level 20  
    Posts: 275
    Help: 37
    Rate: 137
    It may be so
    If Range("F6") = "" and Range("H6") = "" and Range("J6") = "" Then .....
    and if not that
    If (Range("F6") = "" and Range("H6") = "" and Range("J6") = "" ) Then .....
    I haven't used VB for a long time, but in Pascal-type languages, conditions are joined by "and" and "or", etc.
  • ADVERTISEMENT
  • #5 7019010
    Dżyszla
    Level 42  
    Posts: 7077
    Help: 1095
    Rate: 226
    AND na - just F1 in the editor ;)
  • #6 7070472
    walek33
    Level 29  
    Posts: 1015
    Help: 132
    Rate: 81
    In the file you have an example of use If, And in VBA (cell B2) and similar use of formulas If, And Excel (cell B3).
    Attachments:
    • funkcja.xls (20 KB) You must be logged in to download this attachment.
ADVERTISEMENT