AutoFill VBA on last row

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
793
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello - Having an issue modifying the below VBA to work when NOT on the sheet. When attempting to remove activate/select usage I cant seem to get the below to work when not on the sheet. is someone able to help? The problem is I am not on the "compare" sheet right before the action so it tries to paste formulas down on the sheet i dont want it to. then trying to see how to eliminate that last "select."

VBA Code:
    Dim UsdRws As Long

'paste formulas down in Compare
Sheets("COMPARE").Range("F13:U13").Select
UsdRws = Range("A" & rows.count).End(xlUp).row
If UsdRws > 13 Then Range("F13:U" & UsdRws).FillDown
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
The issue is if you are not on the sheet, and don't use the sheet reference when referring to your range, it will default to the active sheet.
So your code should look like this:
VBA Code:
Dim UsdRws As Long

'paste formulas down in Compare
UsdRws = Sheets("Compare").Range("A" & rows.count).End(xlUp).row
If UsdRws > 13 Then Sheets("Compare").Range("F13:U" & UsdRws).FillDown
 
Upvote 0
The issue is if you are not on the sheet, and don't use the sheet reference when referring to your range, it will default to the active sheet.
So your code should look like this:
VBA Code:
Dim UsdRws As Long

'paste formulas down in Compare
UsdRws = Sheets("Compare").Range("A" & rows.count).End(xlUp).row
If UsdRws > 13 Then Sheets("Compare").Range("F13:U" & UsdRws).FillDown
WORKS. Thank you for that!
 
Upvote 0
You are welcome.

Just remember, whenever you want to refer to a range on a sheet that is not the active sheet, you need to include the sheet reference in your range.
Otherwise, it will default to the active sheet.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

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