Last Row

Vincent Thank You

New Member
Joined
Oct 3, 2017
Messages
18
Hello,

The following code is not allowing me to integrate the "lastrow" formula and is creating 0's well past the data range.

On Error Resume Next
With ActiveSheet.Range("N2:N2" & Cells(Rows.Count, 2).End(xlUp).Row).SpecialCells(xlCellTypeVisible)
.Cells.FormulaR1C1 = "=RC[-2]"
.Cells.FillDown

When I do integrate it the way I see fit the formula doesn't preform properly. Thanks!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try this:

Code:
[COLOR=#333333]On Error Resume Next[/COLOR]
[COLOR=#333333]With ActiveSheet.Range("N2:N" & Cells(Rows.Count, 2).End(xlUp).Row).SpecialCells(xlCellTypeVisible)[/COLOR]
[COLOR=#333333].Cells.FormulaR1C1 = "=RC[-2]"[/COLOR]
[COLOR=#333333].Cells.FillDown[/COLOR]
 
Upvote 0
Basically you were adding a leading 2 to the real last row. So if your last row was 20, then the code would run to row 220.
 
Upvote 0
With

Code:
[/COLOR][COLOR=#333333]Cells(Rows.Count, 2).End(xlUp).Row

You are counting rows, say it's 1000.

By having "N2:N" & 1000 you have "N2:N1000".

By having "N2:N2" & 1000 you have "N2:N21000".
 
Upvote 0
Ahhhhh, I see. Thank you for the information. I'm actually trying to drag the formula down to the bottom of the data range to visible cells only. So, with this formula, if it's only 500 rows, it's going to extend that by 500 with more 0's, correct? The
 
Upvote 0
I'm actually trying to drag the formula down to the bottom of the data range to visible cells only

Why would you need to use Filldown as the code already puts the formula in the visible cells?

Code:
On Error Resume Next
ActiveSheet.Range("N2:N" & Cells(Rows.Count, 2).End(xlUp).Row).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=RC[-2]"
On Error Goto 0
 
Last edited:
Upvote 0
It seems to be working, I was just looking for further information as to why. The reason I was trying to fill down was because the data range is a variable, It's not always the same length. I was trying to fill down, visible cells only to the bottom of the data range.
 
Upvote 0
Code:
[COLOR=#333333]Cells(Rows.Count, 2).End(xlUp).Row[/COLOR]

deals with the variable part

it's counting the rows

basically it's the same as selecting the last cell column B and pressing ctrl + up
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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