Hi everybody,
I wonder if someone could help. I'm writing some code to help calculate a variance between actual and target figures. Unfortunately, the spreadsheet sometimes contains . which need to be ignored, if not they skew the calculation. I've used the following code:
Sub ConvertPercentage()
Do
If IsEmpty(ActiveCell.Offset(0, -1)) And IsEmpty(ActiveCell.Offset(0, -2)) Or IsEmpty(ActiveCell.Offset(0, -1)) And ActiveCell.Offset(0, -2) >= 0 Or ActiveCell.Offset(0, -1) And IsEmpty(ActiveCell.Offset(0, -2)) Or ActiveCell.Offset(0, -1) = "." And ActiveCell.Offset(0, -2) = "." Or IsEmpty(ActiveCell.Offset(0, -1)) And ActiveCell.Offset(0, -2) = "." Or IsEmpty(ActiveCell.Offset(0, -2)) And ActiveCell.Offset(0, -1) = "." Then
ActiveCell.Value = ""
Else
Selection.ClearContents
ActiveCell.FormulaR1C1 = "=(RC[-1]-RC[-2])/RC[-2]"
ActiveCell.Select
Selection.NumberFormat = "0.0%"
End If
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell = "End"
End Sub
Unfortunately, i get a run time error. I've tried taking away the value command as "." is obviously not a value but that doesn't work either.
I'm a bit stuck and your help would be much appreciated.
Thanks,
ad
I wonder if someone could help. I'm writing some code to help calculate a variance between actual and target figures. Unfortunately, the spreadsheet sometimes contains . which need to be ignored, if not they skew the calculation. I've used the following code:
Sub ConvertPercentage()
Do
If IsEmpty(ActiveCell.Offset(0, -1)) And IsEmpty(ActiveCell.Offset(0, -2)) Or IsEmpty(ActiveCell.Offset(0, -1)) And ActiveCell.Offset(0, -2) >= 0 Or ActiveCell.Offset(0, -1) And IsEmpty(ActiveCell.Offset(0, -2)) Or ActiveCell.Offset(0, -1) = "." And ActiveCell.Offset(0, -2) = "." Or IsEmpty(ActiveCell.Offset(0, -1)) And ActiveCell.Offset(0, -2) = "." Or IsEmpty(ActiveCell.Offset(0, -2)) And ActiveCell.Offset(0, -1) = "." Then
ActiveCell.Value = ""
Else
Selection.ClearContents
ActiveCell.FormulaR1C1 = "=(RC[-1]-RC[-2])/RC[-2]"
ActiveCell.Select
Selection.NumberFormat = "0.0%"
End If
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell = "End"
End Sub
Unfortunately, i get a run time error. I've tried taking away the value command as "." is obviously not a value but that doesn't work either.
I'm a bit stuck and your help would be much appreciated.
Thanks,
ad