Convert dashes to zero - VBA

NinaE_11

Board Regular
Joined
Aug 18, 2020
Messages
54
Office Version
  1. 2016
Platform
  1. Windows
Hello,
I have a contiguous range of data that I plan to do apply a number of different functions to, however, due to source of material, some of the data points will use a "--" in lieu of zero. I would like to see if there is any VBA language that can convert these dashes to use a "0.00" format instead.

So far, I have tried the following:
Range("B1").currentregion.select
selection.numberformat = "0.00"

However, this does not update the dashes to the 0.00 which allows the functions to work properly. Any help would be much appreciated - thank you!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Maybe I should just try to clear out the "--" altogether. Would that be easier? So it's a blank space - would have the same affect to formula.
 
Upvote 0
My data starts in cell C7, but I replaced the "B1" he provided with the C7 reference.
OK, if you put "C7" instead of "B1" in the MsgBox line of code I sent you, what exactly does the MsgBox return?
 
Upvote 0
It came back with a '45'. Is that meaningful? I am clueless.
That's what I would expect to see, it's the code number for a -
Does this work
VBA Code:
Sub NinaE()
   With ActiveSheet.UsedRange
      .Replace "--", 0, xlPart, , , , False, False
      .Value = .Value
   End With
End Sub
 
Upvote 0
That's what I would expect to see, it's the code number for a -
Does this work
VBA Code:
Sub NinaE()
   With ActiveSheet.UsedRange
      .Replace "--", 0, xlPart, , , , False, False
      .Value = .Value
   End With
End Sub


Thank you - this worked! It didn't change the visual to a 0, but it calculates the formula as it should and I don't get an error anymore! Thank you so much. :)
 
Upvote 0
Glad it's sorted & thanks for the feedback.
 
Upvote 0
$A$1:$H$5
That tells you what your problem was. Your Current Region statement was only selecting A1:H5 in your data (meaning that row 6 is blank and column I is blank). Current Region only selects the contiguous cells, so if you do not pick a cell that is within your data range to start, or if you have completely blanks rows and/or columns in the middle of the data, Current Region will not return all your data.

Fluff's solution looks at the entire usedd range.
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,517
Members
448,968
Latest member
Ajax40

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