Reputation: 163
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?
Upvotes: 0
Views: 787
Reputation: 1983
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
Upvotes: 0
Reputation: 2472
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
Upvotes: 1
Reputation: 2481
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
Upvotes: 0