Fill Blanks

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,134
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
the below code works very well, but if there isn't any blank cells it gives a error, any idea as how to modif the same.


Sub Fill_Blanks()
With Range("M5:M" & Range("J" & Rows.Count).End(xlUp).Row)
.SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C"
.Value = .Value
End With
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Please use
Code:
 tags when pasting code.

First, I don't see the use of 
[CODE][COLOR=#333333].Value = .Value[/COLOR]
It's like saying 1=1. It's always true, it never won't be true, and it won't do anything.

Code:
Sub Fill_Blanks()
On Error Resume Next

With Range("M5:M" & Range("J" & Rows.Count).End(xlUp).Row)
    .SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C"
End With

On Error GoTo 0
End Sub

This would work if this is the COMPLETE Sub. It ignores the code and lets the code continue. If there are more lines than the ones you've provided, I would be hesitant in recommending you this option.
 
Last edited:
Upvote 0
thanks tim, for quick response. No there are not another other lines.
 
Upvote 0
Please use
Code:
First, I don't see the use of 
[CODE][COLOR=#333333].Value = .Value[/COLOR]
It's like saying 1=1. It's always true, it never won't be true, and it won't do anything.

It has a use, it converts the formula to a constant.
 
Upvote 0
Further to what Mark858 said (and irrelevant in this scenario)
If you have a formula that returns "" & you use pastespecial you will end up with a null string in the cell (ie not blank), but using
Code:
[COLOR=#333333].Value = .Value[/COLOR]
will make those cells blank
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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