Filling blank Cell With 0 in Dynamical range .

Panki

New Member
Joined
Aug 7, 2022
Messages
4
Office Version
  1. 2010
Platform
  1. Windows
Below Code is giving me the message of Blank cells in dynamical range. I want to replace all blank cells with "0".

Note - Range should be dynamic on the basis of A2 to last column as per Data and A2 to last Row as per Data .it is not fixed.



Sub Blank_Cell_Alert()
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Name = "MyRange"
ActiveSheet.Name = "MySheet"
If Range("MyRange").SpecialCells(xlCellTypeBlanks).Count > 0 Then
MsgBox ("Please Enter all Employee Data Before you Attempt to Update this Table."), vbCritical, "Incomplete Data!"
Cancel = True
End If
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try this:

VBA Code:
Sub Blank_Cell_Replacement()
Dim MyRange As Range
Dim cel As Variant
Dim ColCount As Long
Dim RowCount As Long
'You don't need to select the cells to make the range, just count them
ColCount = Range("A2", Range("A2").End(xlToRight)).Columns.Count
RowCount = Range("A2", Range("A2").End(xlDown)).Rows.Count + 1 'add one for starting at row 2
'set the range based on your counts
Set MyRange = Range("A2", Cells(RowCount, ColCount))
If MyRange.SpecialCells(xlCellTypeBlanks).Count > 0 Then
    'loop through all the cells in the range
    For Each cel In MyRange
        'if the cell is empty , make it 0
        If cel = "" Then cel.Value = "0"
    Next
End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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