Scan and fill empty cells with zero

pban92

Board Regular
Joined
Feb 26, 2010
Messages
88
Office Version
  1. 2016
Platform
  1. Windows
Hi,

My excel file has 10 columns and different number of cells (rows). The largest column has 291 cells and the shortest column has 10 cells.

I need to write a macro that will scan all 10 columns until it reaches the 300th cell and fills empty cells with zero. So each column contain even number of cells.

Any help would be appreciated.

Many thanks!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try

Code:
Sub Test2()
Dim LR As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
On Error Resume Next
Range("A1:J" & LR).SpecialCells(xlCellTypeBlanks).Value = 0
On Error GoTo 0
End Sub
 
Upvote 0
Try this in your worksheet module

Code:
Sub FillZero()
Application.ScreenUpdating = False
For i = 1 To 10
    For j = 1 To 300
        If Cells(i, j).Value = "" Then
            Cells(i,j).Value = 0
        End If
    Next j
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks all for your kind help!
@MickG, :biggrin: thanks for the magic!
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,220
Members
452,895
Latest member
BILLING GUY

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