Formula Changes After a VBA Paste

OldSwimmer1650

New Member
Joined
Dec 3, 2020
Messages
27
Office Version
  1. 365
Platform
  1. Windows
The change is from $E$2 to $E$3 & $B$2 to $B$3

This formula changes from:
=IFERROR(SUM(FILTER('Garmin Data'!$E$2:$E$5000,ROUNDDOWN('Garmin Data'!$B$2:$B$5000,0)=D324)),"")

to

=IFERROR(SUM(FILTER('Garmin Data'!$E$3:$E$5000,ROUNDDOWN('Garmin Data'!$B$3:$B$5000,0)=D324)),"")
after the below code executes

Windows("Weight_Ex.xlsm").Activate
Sheets("Garmin Data").Select
Range("A2").EntireRow.Select
Selection.Insert Shift:=xlDown
Range("A1").Select
Application.CutCopyMode = False

I know the insert is causing the error, but I don't know how to fix it.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
What cell is your formula in to start with, and what cell is it in after the insert?
 
Upvote 0
Here is one option.
Excel Formula:
=IFERROR(SUM(FILTER(INDIRECT("'Garmin Data'!$E$2:$E$5000"),ROUNDDOWN(INDIRECT("'Garmin Data'!$B$2:$B$5000"),0)=D324)),"")

Here is another that should work as long as you are not inserting before row 1.
Excel Formula:
=IFERROR(SUM(FILTER(OFFSET('Garmin Data'!$E$1,1,0,4999),ROUNDDOWN(OFFSET('Garmin Data'!$B$1,1,0,4999),0)=D324)),"")

INDIRECT and OFFSET are volatile functions, which means Excel cannot tell in advance whether a particular change on the worksheet will affect the results, so it has to recalculate them every time there is any change. If you just have this formula once it's no problem, but if you have it thousands of times it could slow down calculation.
 
Upvote 0
Solution
Here is one option.
Excel Formula:
=IFERROR(SUM(FILTER(INDIRECT("'Garmin Data'!$E$2:$E$5000"),ROUNDDOWN(INDIRECT("'Garmin Data'!$B$2:$B$5000"),0)=D324)),"")

Here is another that should work as long as you are not inserting before row 1.
Excel Formula:
=IFERROR(SUM(FILTER(OFFSET('Garmin Data'!$E$1,1,0,4999),ROUNDDOWN(OFFSET('Garmin Data'!$B$1,1,0,4999),0)=D324)),"")

INDIRECT and OFFSET are volatile functions, which means Excel cannot tell in advance whether a particular change on the worksheet will affect the results, so it has to recalculate them every time there is any change. If you just have this formula once it's no problem, but if you have it thousands of times it could slow down calculation.
Thank you very much. It's contributors like you that make this site work. I've learned something today. Thank you!
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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