0

So I'm getting an error with some code and I don't know how to get around it

Range("K" & varOffset).Select
           Output = If (ISBLANK(H2), "No", "Yes")      <----------Shows up red
           ActiveCell.FormulaR1C1 = Output`              

How do I make this if statement work?

3 Answers 3

1

Looks like you are trying to use the worksheet version of IF.

Try VBA IF block

If IsEmpty(H2) Then
    Output = "No"
Else
    Output = "Yes"
End If
Sign up to request clarification or add additional context in comments.

1 Comment

So I also want it to update when I change "H2" in the sheet after I do the macro, any ideas?
0

Try this

Formulae in Excel is not VBA. VBA has its code structure that needs to be adherered to

Range("K" & varOffset).Select
If trim(Range("H2")) = "" then 
  output = "No"
else 
  output =  "Yes"
end if
ActiveCell.FormulaR1C1 = Output 

2 Comments

Thank you very much, this helped a lot! However, I realized I made a huge mistake in my question, I actually want it to check two cells to the left of the current cell (Instead of always H2). I also want it to update when I change that information, as of right now the cell stays as "yes" or "no" regardless of whether H2 has changed. Would this be possible?
So I figured out how to make the offset, but need it to update when I add information in.
0

the below will avoid the need to select a cell which should always be avoided. It also avoids the need for the output variable

with Range("K" & varOffset)
    If trim(Range("K" & varOffset).offset(0,-2).value)="" then'If blank
        .value= "Yes"
    else
        .value= "No"
    endif
end with

1 Comment

So I made a mistake. I actually want it to compare 2 cell to the left of the current cell.

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.