VBA to fill the empty cells above from the value below.

danbates

Active Member
Joined
Oct 8, 2017
Messages
377
Office Version
  1. 2016
Platform
  1. Windows
Hi,

Please could someone help me out?

I am trying to get a VBA code that fills all the empty cells above in column G with the same value that is below.

So lets say 'DB' is in cell G20 and 'AL' is in cell G10.

I would like the code to fill cells G19:G11 with 'DB'

Any help would be much appreciated.

Thanks

Dan
 
The error is: Run-time error '1004': No cells were found.

and when I debug, it highlights this line
Code:
.SpecialCells(xlBlanks).FormulaR1C1 = "=R[1]C"
That indicates that there are no blank cells in the range being considered.
.. which is why I said right back at the beginning ..
Assuming ..
- the blank cells are truly blank
Are you convinced there are blank cells in the range being considered?
Just one possibility: The cells that look blank actually contain formulas returning ""?

The following question still stands:
Can you give us a small set of dummy data for which the code fails?
 
Last edited:
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi Peter,

Right ok. I now see where I have gone wrong in my original question.

There are 2 ways the worksheet can be entered.

Sometimes there will be one entry meaning no blanks cells and sometimes there will be multiple entries and that's when there will be blank cells in columns G:I but starting from row 3.

I hope this clears things up a little and I am sorry for the inconvenience.

Thanks

Dan
 
Upvote 0
Sometimes there will be .. no blanks cells and sometimes there will be .. blank cells in columns G:I but starting from row 3.
Try
Code:
Sub FillBlanks_v2()
  Dim Rng As Range, RngBlanks As Range
  
  Set Rng = Range("G3", Range("I" & Rows.Count).End(xlUp))
  On Error Resume Next
  Set RngBlanks = Rng.SpecialCells(xlBlanks)
  On Error GoTo 0
  If Not RngBlanks Is Nothing Then
    RngBlanks.FormulaR1C1 = "=R[1]C"
    Rng.Value = Rng.Value
  End If
End Sub
 
Upvote 0
Hi Peter,

I have run your code but it still triggers the Run-time error '1004': No cells were found. when entering a single entry.

It highlights this line:
Code:
Set RngBlanks = Rng.SpecialCells(xlBlanks)


Thanks again

Dan


 
Upvote 0
.. when entering a single entry.
Can you explain exactly what that means?

Have you included the blue line in the code?
Rich (BB code):
On Error Resume Next
Set RngBlanks = Rng.SpecialCells(xlBlanks)
 
Upvote 0
Hi Peter,

I did copy and paste your code before but I have done it again tonight and everything seems to be ok, so thank you for all your help.

It really is appreciated.

Thanks again

Dan
 
Upvote 0

Forum statistics

Threads
1,216,515
Messages
6,131,111
Members
449,621
Latest member
feaugcruz

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