I need a code altering that auto fills from the bottom up.

danbates

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

Please can someone help me?

I have the following code that fills any blank cells above the last cell with a value and it fills the blank cells above with that value.

At the moment it will fill column G from the bottom up to cell G7.

Example:
If cell G500 has "X" and cell G250 has "Y" in it and I execute the code, the cells from G500:G251 will have a"X" and cells G250:G7 will have a "Y".

I would like the code to still fill the same but I would like it to stop once it sees another value.

Example:
If cell G500 has "X" and cell G250 has "Y" in it and I execute the code, the cells from G500:G251 will have a"X" and then stops.

Here is my code:

VBA Code:
Sub FillBlanks()

  Dim Rng As Range, RngBlanks As Range

  Set Rng = Range("G7", Range("G" & 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

Any help would be appreciated.

Regards

Dan
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Give this macro a try...
VBA Code:
Sub FillLastBlanksOnly()
  Dim BlnkRng As Range, ConstRng As Range
  Set BlnkRng = Range("A1", Cells(Rows.Count, "A").End(xlUp)).SpecialCells(xlBlanks)
  Set ConstRng = Range("A1", Cells(Rows.Count, "A").End(xlUp)).SpecialCells(xlConstants)
  BlnkRng.Areas(BlnkRng.Areas.Count).Value = ConstRng.Areas(ConstRng.Areas.Count)(1).Value
End Sub
 
Upvote 0
Hi Rick,

Your code works perfectly thank you but I've had a thought.

Is it possible to have the code looking from A500:A1 instead of looking at the whole of column A?

Thanks again

Dan
 
Upvote 0
My code does not look at the whole of Column A... it looks from the last cell with data upward. Did you misunderstand that or are you saying you have data and blanks in cells past cell A500 that you want to ignore? If the latter, then you have to tell us what to do when, say, cells A491:A500 are blank, A490 is not blank and cells A480:A489 are blank... what is the last blanks to be filled, cells A480:A489 or cells A491:A500?
 
Upvote 0
Hi Rick,
I did misunderstand your code and yes I have a 'helper' row (Row 1000) that I would like your code to ignore.
My data finishes at row 500. There will be no data in any columns from row 501:999.

Thanks again for your help.

Dan
 
Upvote 0
Given what you posted, this should work for you...
VBA Code:
Sub FillLastBlanksOnly()
  Dim BlnkRng As Range, ConstRng As Range
  Set BlnkRng = Range("A1", Cells(501, "A").End(xlUp)).SpecialCells(xlBlanks)
  Set ConstRng = Range("A1", Cells(501, "A").End(xlUp)).SpecialCells(xlConstants)
  BlnkRng.Areas(BlnkRng.Areas.Count).Value = ConstRng.Areas(ConstRng.Areas.Count)(1).Value
End Sub
 
Upvote 0
Hi Rick,

Absolutely perfect thank you. I really appreciated it.

Regards

Dan
 
Upvote 0

Forum statistics

Threads
1,215,710
Messages
6,126,396
Members
449,312
Latest member
sweetfriend9

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