Debug Filldown (THIS POST IS NOW CLOSED)

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
833
Trying to fill down a value that appears in cell A2. The following code errors at the line:

Set FillRange = Range(Cells(x, y), Cells(r - 1, y))

Tried to debug it but to no avail. Any suggestions with the code welcomed.

Dim FillRange As Range
Dim FillWith As Range

Dim x As Long
Dim y As Long
Dim r As Long
Dim EndRow As Long

EndRow = Cells.SpecialCells(xlCellTypeLastCell).Row
x = 2 'Start at row 2
y = 1 'Column equals A

Do Until x > EndRow

r = Cells.SpecialCells(xlCellTypeBlanks).Row

Set FillRange = Range(Cells(x, y), Cells(r - 1, y))Set FillWith = Cells(x, y)
FillWith.AutoFill FillRange

x = r + 1
Loop
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Re: Debug Filldown

Jak said:
Trying to fill down a value that appears in cell A2. The following code errors at the line:

Set FillRange = Range(Cells(x, y), Cells(r - 1, y))

Set FillRange = Range(Cells(x, y), Cells(r - 1, y))Set FillWith = Cells(x, y)
FillWith.AutoFill FillRange

x = r + 1
Loop

Needs a colon between the two set commands if they're on the same line of code

Set FillRange = Range(Cells(x, y), Cells(r - 1, y)):Set FillWith = Cells(x, y)
 
Upvote 0
thanks for that Egress1

Still errors on that line, no filldown
 
Upvote 0
Jak said:
thanks for that Egress1

Still errors on that line, no filldown

Ok, now your error occurs when the value of r = 1. The statement
Cells(r-1,y) is causing your error as r-1 = 0

Wash
Rinse
Repeat
 
Upvote 0
Jak said:
thanks for that Egress1

Still errors on that line, no filldown


What is special about the blank rows? Are you trying to fill just the blank cells or are you trying to fill everything BUT the blank cells?
 
Upvote 0
I am trying to fill down blank cells. I use an input method to enter a value in cell "A2" and I need it to filldown to the last row in the used range. In the past I would refrence a column that always contained data and use code such as:

batchnumber = InputBox("Enter the Batch Number:")

Dim z As Range
Set z = Range("D2")
While Not IsEmpty(z.Value)
z.Offset(0, -1).Value = batchnumber
Set z = z.Offset(1, 0)
Wend
Set z = Nothing

The problem with this method is that the data I have been working with of late has numerous blank cells dotted around throughout and the filldown fails when a blank cell is encountered, hence the new approach.

HTH
 
Upvote 0
Well how about something like this?

endrow = Cells.SpecialCells(xlCellTypeLastCell).Row
[a3].Select
For k = 1 To endrow - 2
ActiveCell.Value = [a2]
ActiveCell.Offset(1, 0).Activate
Next k
 
Upvote 0
Many thanks Egress1

That works great. Thanks for all your input.
 
Upvote 0
Alternatively, some one-liners (this post has just been re-opened) :

EITHER :-
[A2].Copy Range([A3], Cells(Cells.SpecialCells(xlCellTypeLastCell).Row, 1))

OR :-
Range("A2:A" & Cells.SpecialCells(xlCellTypeLastCell).Row).FillDown
 
Upvote 0
Thanks Ponsonby

Just noticed your contribution, sorry I closed the post early. Thanks for the excellent tips. :D
 
Upvote 0

Forum statistics

Threads
1,221,691
Messages
6,161,322
Members
451,696
Latest member
Senthil Murugan

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