All I am trying to do is to get a cell to show the percentage increase/decrease between two other cells. The code works fine when there are numerical values in there but after pressing the reset' button (which sets the cell values to "-"), it wont work even though I have worked the "-" scenario into my code:
Private Sub PerChange(ByVal burn1 As Range, burn2 As Range, change As Range)
If burn1.Value And burn2.Value = "-" Then
change.Value = "-"
Else
change.Value = (burn1.Value / burn2.Value) - 1
End If
End Sub
It is the bold line where the error occurs even though the values of both are "-"
I also tried swapping the bold line for:
**If IsNumeric(burn1.value and burn2.value) = False**
and it still stopped with a TYpe mismatch on this line, even though the whole point of IsNumeric is to check for non numeric types!!
Please advise as I am tearing my hair out...
burn1.Value = "-" And burn2.Value = "-"? AlsoIf IsNumeric(burn1.value and burn2.value) = Falseis valid but definetly not what you want. TryIf Not IsNumeric(burn1.value) and Not IsNumeric(burn2.value)- z̫͋IsNumeric(burn1.value and burn2.value)says that you want to know if the expressionburn1.value and burn2.valueis a numeric value. Using theAndoperator on variant values is error prone and not very intuitive, and definitely not what you are trying to achieve. For example, if one of the cell value is a string which cannot be converted to a number (ex. "abc"), you will get an error. Or if your cells are empty thenEmpty and Emptywill actually return zero which is a numerical value. So yes, useIsNumericon expression you can predict, like a single variable - z̫͋