If cell blank = $0.00?

EdaddyJ

Board Regular
Joined
Feb 14, 2007
Messages
115
Can you tell me whats wrong here? I know it has something to do with the range. Or give me a better solution?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Set rng = Sheets(1).Range("=D23:E304")
For Each cell In rng
If cell.Value = 0 Or cell.Value = Null Or cell.Value = " " Then
cell.Value = "$0.00"
End If
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Why do you use the SelectionChange event? Just curious...
Must this really be evaluated everytime you change selection?
Seems like overkill to me... why not use the Change event, won't
fire as often, so that this sub will not slow things down too much?

As for the Range: change
("=D23:E304") to ("D23:E304")
the Sheets(1). is also unnecessary I think... try to remove that as well.
 
Upvote 0
I don't know why I do things I just do them =-)
Someone gave me this solution before so I copied it from my other sheet and tried to duplicate the same results. Problem is I am trying to get the results in cells that contain formulas so #DIV/0! is still me result. Do you have any suggestions?
 
Upvote 0
it is telling me variable not defined and highlighting CELL

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Set rng = Range("D23:E304")
For Each cell In rng
If cell.Value = 0 Or cell.Value = Null Or cell.Value = " " Then
cell.Value = "$0.00"
End If
End Sub
 
Upvote 0
Could you post a sample of what data you have, and what it should become after whatever macro had its way with it? :)
Do you actually want to remove the formulas that give error-results and put $0.00 in their place? Or only put $0.00 in really empty cells and hide results from formulas only IF they give an error?

There is some more input from you required before we have an idea of what you want to achieve...
 
Upvote 0
A B C D
1 Name Job% Labor Labor Burden
2 Erin 100% 1000 350
3 Job 1 50% 500 175
4 Job 2 25% 250 87.5
5 Job 3 25% 250 87.5

I enter in the Labor and Labor Burden totals in cells C2 and D2 and in all of column C and it calculates the percentage then the Labor Burden dollar. But if C2 is blank it gives me an error. I need it to show $0.00.

I hope I explained that well.
 
Upvote 0
I think you wouldn't need VBA to do that...
You can use worksheet functions like IF to do that...
What is the formula you are using that gives the error?
 
Upvote 0
That's a good solution but I was trying to do it all at once. Other wise I have 300 if statements to write in 300 different cells. Which I could do in about the same amount of time as figure this out but I was hoping to figure out a better way for later sheets.
 
Upvote 0
you'd have to write the if-statement once, then doubleclick the autofill handle and you'd be done... doesn't get much easier I guess...
 
Upvote 0

Forum statistics

Threads
1,214,426
Messages
6,119,417
Members
448,895
Latest member
omarahmed1

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