.End(xlUp).Row need to stop at defined row

ceytl

Board Regular
Joined
Jun 6, 2009
Messages
114
Office Version
  1. 2016
Platform
  1. Windows
Hello,

Currently this code goes through the entire F column, but I only want it to go to F1:F900

How would I do that?

Thanks!

VBA Code:
Sub SumColumn()

Sheets("Sales").Select
Dim Lr As Long, i As Long
Lr = Range("F" & Rows.Count).End(xlUp).Row
For i = 25 To Lr
If Range("F" & i).HasFormula() = True Then Range("F" & i).AutoFill Destination:=Range("F" & i & ":G" & i)
Next i
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Your code works fine in principle. What it does it to set Last Row to be the last used cell in column F.
If you only want it to go to row 900 then you need to either set the range to only go to 900 or make sure that every cell below row 900 in column F is empty.
 
Upvote 0
This will limit it to row 900 as a maximum
VBA Code:
Sub SumColumn()

Sheets("Sales").Select
Dim Lr As Long, i As Long
Lr = Range("F" & Rows.Count).End(xlUp).Row
If Lr > 900 Then Lr = 900
For i = 25 To Lr
If Range("F" & i).HasFormula() = True Then Range("F" & i).AutoFill Destination:=Range("F" & i & ":G" & i)
Next i
End Sub
 
Upvote 0
Solution
This will limit it to row 900 as a maximum
VBA Code:
Sub SumColumn()

Sheets("Sales").Select
Dim Lr As Long, i As Long
Lr = Range("F" & Rows.Count).End(xlUp).Row
If Lr > 900 Then Lr = 900
For i = 25 To Lr
If Range("F" & i).HasFormula() = True Then Range("F" & i).AutoFill Destination:=Range("F" & i & ":G" & i)
Next i
End Sub

Thank you!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,457
Messages
6,124,941
Members
449,197
Latest member
k_bs

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