How to make an IF Statement with OR and an empty cell in Excel VBA -
i trying make if statement in vba script. wants achieve copy content 1 sheet ("database") sheet ("search"), given fulfilment of if statement.
the script starts defining variables ("country", "category") dependent on user input on cells "e5" , "e7" of "search" sheet. defines final row if statement run until row:
country = sheets("search").range("e5").value category = sheets("search").range("e7").value finalrow = sheets("database").range("a200000").end(xlup).row
after this, script establishes condition: if inputted values (in cells "country" , "category") matched content on cells of "database" sheet, values on sheet should copied "search" sheet:
for = 2 finalrow if sheets("database").cells(i, 1) = country , _ sheets("database").cells(i, 3) = category sheets("database") .range(.cells(i, 1), .cells(i, 9)).copy end sheets("search").range("b600").end(xlup).offset(1, 0).pastespecial xlpasteformulasandnumberformats end if next
i add additional condition if statement or statement. make if user not fill "category" cell, values still copied 1 sheet another. in terms of code, added part between ** not working:
for = 2 finalrow if sheets("database").cells(i, 1) = country , _ sheets("database").cells(i, 3) = category **or category = ""** sheets("database") .range(.cells(i, 1), .cells(i, 9)).copy end sheets("search").range("b600").end(xlup).offset(1, 0).pastespecial xlpasteformulasandnumberformats end if next
apart this, working out fine. have idea of might doing wrong? thank you!
i'd avoid or
entirely if it's giving issues. putting space in " "
literally looking space value, if mean blank use ""
or isempty(category)
:
for = 2 finalrow if category = "" if sheets("database").cells(i, 1) = country sheets("database") .range(.cells(i, 1), .cells(i, 9)).copy end sheets("search").range("b600").end(xlup).offset(1, 0).pastespecial xlpasteformulasandnumberformats end if else if sheets("database").cells(i, 1) = country , _ sheets("database").cells(i, 3) = category sheets("database") .range(.cells(i, 1), .cells(i, 9)).copy end sheets("search").range("b600").end(xlup).offset(1, 0).pastespecial xlpasteformulasandnumberformats end if next
Comments
Post a Comment