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?
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
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.