Easy replace macro

Leon_UK

New Member
Joined
Mar 11, 2008
Messages
38
Hi all.

I want to create a macro which will replace all cells in a selected range with '0' Zero.

all help welcome?

Cheers
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Update.

I've created this:

Code:
Sub Change_Blanks()
    Dim myRange As Range
    Set myRange = Worksheets("Sheet1").Range("A1:D10").Cells
    
    For Each cell In myRange
        If cell.Value = "" Then cell.Value = 0
    Next
End Sub

How do I remove the need to specify a range so works with any selected cells I have when the macro is ran?
 
Upvote 0
Altho, if it's blanks your targeting, you have an faster option:

Code:
Dim rBlanks As Range
On Error Resume Next
Set rBlanks = Selection.SpecialCells(xlCellTypeBlanks)
On Error Goto 0
If Not rBlanks Is Nothing Then rBlanks.Value = 0
 
Upvote 0

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,077
Latest member
Jocksteriom

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