Fixing equaton to cell address despite inserting rows!

Niemsters

New Member
Joined
Jul 29, 2010
Messages
5
Hey guys, first time poster, I've got to say for every question answered, there are probably 20+ people that it helps, so good job making the world a better place!

My problem:
my worksheet includes 24 rows of data (Dates in Column A, Data in Column B). My macro inserts a row (at A4) and pastes data in B4 which is in a range used for an equation in F3 (=100*STDEV($B$4:$B$15)). However when I instert a row it pushes the equation to look at B5:B16 instead of staying locked on B4:B15.

I'm not sure if I need to fix this with VBA or just in Excel... either's fine with me.

My Code:
'Insterst row and auto fills date to new row
Range("A4").Select
ActiveCell.EntireRow.Insert
Range("A5:B8").Select
Selection.AutoFill Destination:=Range("A4:H9"), Type:=xlFillDefault
'Copeis Data
Sheets("Sheet1").Select
ActiveCell.Offset(0, 6).Select
Selection.Copy
Sheets(Sheet2).Select
Range("B4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Any help is appreciated, I'm sure it's a pretty simple problem.
 

Some videos you may like

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Sandeep Warrier

Board Regularmmmm Pizza
Joined
Oct 31, 2008
Messages
2,672
Hi & welcome to the Board!

The easiest way, AFAIK, since you are already using a macro, would be to code the formula in the macro.

For example, try inserting the line

Code:
Range("F3").Formula = "=100*STDEV($B$4:$B$15)"
in your code.
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
10,628
Office Version
2019
Platform
Windows
Welcome to the board!

My personal choice would be change the formula in F3 to

=100*STDEV(INDIRECT("B4:B15"))

I'm sure others will have some alternative solutions for you.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,137
Messages
5,509,379
Members
408,733
Latest member
Maxwell0454

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top