Filling blank Cell With 0 in Dynamical range .

Panki

New Member
Joined
Aug 7, 2022
Messages
3
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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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,214,593
Messages
6,120,435
Members
448,962
Latest member
Fenes

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