Macro - IsEmpty and Offset problems when trying to find "."

ad19

New Member
Joined
Dec 3, 2009
Messages
7
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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Really hard to read all that code, but couldn't you just loop through your range first, and replace all "." with ""?

If Cell(x,y) = "." Then Cell(x,y) = ""
 
Upvote 0
The only problem is that some cells contain values to one or two decimal places and so using replace will unfortunately cause problems. Unless there's a way to ignore certain cells with decimal points?
 
Upvote 0
Sorry, I assumed from your earlier code that you were only testing for cells equal to ".". I don't see anything in your code about dealing with decimal numbers.

I'm only proposing if a cell is equal to ".", then replace it with a blank.

Can you be a little more clear about what you are trying to do?
 
Upvote 0

Forum statistics

Threads
1,223,710
Messages
6,174,019
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top