type mismatch error in for each cell in selection

bbrimberry

New Member
Joined
Mar 23, 2016
Messages
34
I'm hoping someone could help me solve this type mismatch error.

I have is the simple macro below.

how can I solve for an #N/A in the selection? I would like an #N/A just to be a 0
if there is an #N/A in the selection I get a type mismatch error


Sub cellfix

For Each cell In Selection

If cell = " " Then Exit For

If cell = "" Then Exit For

cell.Value = "'" & Right("0000000" & cell.Value, 7)


Next



End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
VBA Code:
If IsError(cell.Value) then
    Cell.Value = 0
Else
    cell.Value = "'" & Right("0000000" & cell.Value, 7)
End If
 
Upvote 0
Solution

Forum statistics

Threads
1,215,477
Messages
6,125,036
Members
449,205
Latest member
Eggy66

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