# AVERAGE Formula/VBA With Changing Range (up To Blank Row)

Aug 30, 2006

I have a list of 400 cells all in column A. Is there a way to have XL divide them up so that 100 are in column A, 100 in column B, etc., while still treating them like a single column (e.g. Sort will sort them all together)?

## Build Average Formula Based On Changing Criteria

Oct 16, 2011

Objective: to create an average variance among exact match RevCode

Example: all RevCodes with "666" should be used to make an average variance statistic

Situation: All RevCode's are not in similar group counts and this creates incorrect averages with a standard formula.

Set of Data

RevCode Observed Expected Variance RevCodeMean
666 200 220 -9.091%
666 205 220 -6.818%
666 207 220 -5.909%
777 500 355 40.845%
767 505 505 0.000%
668 100 105 -4.762%
668 105 105 0.000%

Formula that generates average variance between exact match revenue codes:

=(SUM(B2:B4)-SUM(C2:C4))/SUM(C2:C4)

The solutions can be in VBA or within the spreadsheet either way.

## Compute Average Formula With Blank Cells

Jul 25, 2013

Is it possible to show "0" zero in the total average column without inputing zeros in the blank cells in row B3:E3 & B4:E4? There are months we receive no boat & RV orders, so those months wll be zero most of the time. Instead of having #DIV/0! it show 0, without having to input zero in cells to compute the average.

A
B
C
D
E
F

1

Jan
Feb
Mar
April
Total Average

[Code] .......

## Excel 2007 :: Average Of Set Range - Display Blank If Cell Contains 0

Mar 13, 2013

I have searched and trying to manipulate various formulas with no success...

I am entering an AverageIF formula into cell J15

I want to calculate the average of the folllowing ranges cells J5:J8,J10:J13

However, I want the cell J15 to display blank if cell J14=0

On reflection I am unsure an AverageIF formula is even correct.

## Formula To Average Numbers Leaving Out Blank Cells

May 26, 2009

Here is the formula I am using however it interprets the blank cells as 0% and includes it in the average. To make it more difficult there will be some 0%'s.

## Average Formula Dropping Lowest Value Or Blank Cell

Jun 5, 2007

I need to get a formula to calculate the average of the best 3 scores out of 4, but there is some that do not have a value in a cell (so some are only out of 3 scores not 4) and if i simply drop the lowest value and sum the rest, it will incorrectly calculate the average.

## Stop Graph From Changing Named Range To Formula Range

Sep 8, 2006

I am trying to create a graph for a range of data that updates monthly (adding an extra month each time). I wanted the graph source data to update automatically each time the data is refreshed so used an OFFSET formula to identify a named range. I then point the graph to the named range as the source data.

When I enter the range as the source data the graph picks it up. However, when I re-enter the source data option on the graph it has converted the named range into a cell written range (ie. replaces "=QUALITY" with "='Front page'!\$B\$7:\$J\$10" - which therefore will not update when the range increases.

## Add Formula Via Macro On Changing Range

Oct 25, 2006

I’m wondering if it possible to have a variable in a Formula. I was looking around, but non of the other examples I found was working. The code I was trying is:

Sub All()
Dim lngDataRows As Long
Dim lngDataRowsSum As Long
lngDataRowsSum = Range("A5").End(xlDown).Row
Range("A" & lngDataRowsSum).Offset(1, 0).FormulaR1C1 = "Sum"
Range("M" & lngDataRowsSum).Offset(1, 0).FormulaR1C1 = "=sum(M6:M & lngdatarowssum)"
End Sub

Another code I tried was from this thread

Sub All()
Dim lngRowsBottom As Long
Dim lngRowsTop As Long
lngDataRowsSum = Range("A5").End(xlDown).Row
Range("C10").formula = "=sum(R["&lngrowstop&"]C:R["&lngrowsbottom&"]C)"
End Sub

The error message is: “Compile error: Expected: enf of statement” and the part “[C:R[“ is highlighted. Tried various ways to solve it but nothing was working.
Does anyone of you know how to get it up and running?

## Average Formula For Rolling Range?

Jan 24, 2014

I am trying to create a formula that looks for the last populated cell, counts 12 cells back and returns an average for all of the cells in that range. I know I have done this before with some combination of INDEX and COUNT, but I can't seem to remember how I did it and my experimenting is not proving fruitful.

Attached is a simplified version of the layout I am working with

## Formula To Average Cells In A Range

Nov 13, 2008

There are words in a cell and to its right is a number.

I have a name in P5. I need a formula in Q5 to add all the numbers
next to the same name in Range B4:O46.

Michael

## Change Formula Range Without Changing The Contents?

Aug 21, 2012

I'm using the formula =SUMIF(F18:F18,"LY",G18:G18), =SUMIF(F18:F18,"KT",G18:G18), and so on.

I want to change the range to: =SUMIF(F7:F18,"LY",G7:G18), =SUMIF(F7:F18,"KT",G7:G18), and so on.

I can do it manually, but it's 20 rows.

Is there a way where i can change the formula range on the first and copy it down, without also copying the initials, (etc. "LY") ?

## Stop Macro From Changing Range In Formula

Jul 6, 2006

If I have a formula that uses cells that are currently blank - and then run a macro that puts data into those cells - the original formula cell ranges change - even if I put \$ within the ranges.

i.e.

Cell A1 has formula = sumproduct(e1:e10>10)
Currently cells E1:E10 are empty

Run the macro

E1:E10 now has data in.

But formula in cell A1 now reads something like =sumproduct(E13:E23>10) or could read =sumproduct(Ref#>10)

## Changing Single Formula Range With Input Values?

Aug 7, 2014

I have data in column A and formula in D2 is =MAX(A1:A1)

If i enter 12 in B2 cell
....... and 5 in C2 cell formula in D2 should change to =MAX(A12:A17)

If i enter 140 in B2 cell
........and 30 in C2 cell formula in D2 should change to =MAX(A140:A170)

I tried entering INDIRECT function inputting value in B2 as A12 instead only 12 but not fully succeeded

## Vlookup Formula Changing Lookup Range Automatically

Apr 9, 2009

As I copy and past my lookup formula down the page it is changing the lookup range which I think is what is giving me so many #N/A results. My first Formula is
=IFERROR(VLOOKUP(A2,Coors2!A2:D3765,3,FALSE),IFERROR(VLOOKUP(A2,'AB2'!A2:C13944,3,FALSE),(VLOOKUP(A2 ,'WM2'!A2:C4843,3,FALSE))))

Then for instance at line 59 the formula is
=IFERROR(VLOOKUP(A59,Coors2!A59:D3822,3,FALSE),IFERROR(VLOOKUP(A59,'AB2'!A59:C14001,3,FALSE),(VLOOKU P(A59,'WM2'!A59:C4900,3,FALSE))))

## IF Formula - Get Average Of Only Values In That Range Not Including Blanks

Nov 21, 2011

I am looking for a formula for the following:

If there is nothing is U6:W6 return blank

Otherwise sum the contents of Bf6:BH6 and divide by the number of cells that are not empty in the range U6:W6 (to get an average of only the values in that range not including blanks).

## Index Match - Formula Changing If Source Range Modified

Apr 24, 2014

I am trying to monitor the status of a cell on another sheet and autopopulate a cell depending on that information. The formula works well until I give the spreadsheet to a 3rd party and the formula ranges change after they paste new data to the source sheet. I have tried locking and password the formula cells but they change range regardless!

Here is the formula from the first cell.

[Code] ......

It scans for a number in an adjacent cell. If the number is present on the sheet 'Test', it autopopulates the cell with a string from the source sheet. The cell remains blank until there is data present.

If I cut data from row 6 and paste it to row 17, the formula cahnges itself to:

[Code] ........

How I can lock down this formula so that the ranges remain the same i.e. \$AT\$6:\$AT\$26, despite changes on the source sheet? I have tried F4 to toggle relative and absolute references and this has made no difference.

## Formula: Average Value Of Cells Left Of Highest N Values In Above Column Range

Sep 24, 2006

I need a cell formula that will (a) identify the highest N values in an above specified column range, (b) color the interior of those N cells (I suspect that this is not possible), and most importantly (c) return the average value of N corresponding cells, where the corresponding cells are located on the same rows as the identified N high value cells but in a specified column to the left (not necessarily adjacent)

Does anybody know what this formula would look like?

Example:

-----------------------
...| A | B | C | D | E | F |
-------------------------
1 |....| * |.........| 7 |...
-------------------------
2 |....................| 2 |...
-------------------------
3 |....| * |.........| 6 |...
-------------------------
4 |....................| 1 |...
-------------------------
5 |....| * |.........| 5 |...
-------------------------
6 |....................| ? |...
-------------------------

? = average of B1,B3,B5 where (N = 3) and (specified column to the left = B)

## Formula To Average Range Of Cells And Copying It To Calculate Next Range Of Cells?

Mar 17, 2014

I have a row data corresponding to the measuring of load cell per min and I need to average the values per hour. So I have a column B for the date (from 1-01-2013 to 31-01-2013, column C for the time (0:00:00 to 23:59:00), and D de values per min I want to average. I have to do the same for the rest of the month of 2013 (February, ...., December).

I would like to know if there is a way to create a formula to calculate the average of the first 60 values (to get the average of the first hour of 1-01-2013), and then copy it to get the average of the following 60 (average of the second hour in 1-01-2013) and so on.

If there is no way to do it, I would like to know if I can do it using functions like average, match, index, offset, what would be the best match of those functions.

I also tried it by doing the analysis in another tab and using the function "averageifs" with two criterias: one for the date (example 01-01-2013) and another one for the hour (example 0:00:00), but it didnt work, it show error: #value. I inserted an extra column in the data tab with just the hour (example 0:00:00) in front of the corresponding column with (example 0:01:00, 00:02:00, etc)
Equation I used for this:

=AVERAGEIFS('Data (min)'!D\$6:D\$43206,'Data (min)'!\$A\$6:\$A\$44646,A6,'Data (min)'!\$B\$6:\$B\$44646,B6)
=AVERAGEIFS(TAB AND COLUMN WHERE THE RAW DATA IS,RANGE OF CRITERIA 1,CRITERIA 1,RANGE CRITERIA 2,CRITERIA 2)

## Fill A Range With Formula If Blank

Mar 6, 2012

I am trying to add the following code to fill in a certain range only if the range is blank. I can get it to fill in with the formula but it will still enter over if the cell already contains information.

Code:

Sub YTD()

Dim isempty As Boolean
isempty = True

For Each cell In Sheets("YTD%").Range("December").Cells
If cell.Value! = "" Then isempty = False

[Code] .......

## Formula To Tell If Range Has All Blank Cells In It?

Nov 13, 2012

I have a spreadsheet where I want to filter out a row if the entire row has zeros across all the columns. I cannot just use a Sum() formula because some of the numbers are negative and there is a chance it could zero the sum out.

Currently to do this I am using the following to tell if there are values in each of my rows:

Code:
ABS(K3)+ABS(T3)+ABS(U3)+ABS(V3)+ABS(W3)+ABS(Z3)+ABS(AC3)+ABS(AF3)

Is there any way to write a formula where I don't have to keep adding to the formula when I add another column?

## VBA Dynamic Range Till First Blank But Cells Contain Formula?

Jul 22, 2014

I've normally just dynamically selected a range using the xldown feature but because this row contains formula it goes always down to the bottom of the formula instead of the last cell which isn't blank.

How would i go about generating this dynamic range that stops at the first cell that contains no value (but has a formula)? Perhaps a do while loop which looped down until it hit the first blank and then assigned the cells it had looped through as the range?

## VBA - Insert Formula With Sheet References In All Blank Cells In Used Range?

Sep 9, 2013

I am try to get the following VBA macro to work; however, I keep getting hung up on errors regarding the formula I am trying to input. It is getting hung up on the apostrophes and dollar signs. I am fairly new to VBA so I am lost when it come to converting my sheet formulas to VBA.

Code:

With ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks)
.Value = .Value
End With

## Formula To Check Range To Make Sure All Cells Are Either Blank Or 11 Characters Long

May 8, 2012

I need a formula that will search the range D8-D100 to confirm that all cells within that range are either 11 characters in length or blank. I will use it inside of an error message that will look something like this:

=IF(****formula that checks to make sure all of the cells in that range are blank or 11 characters****=TRUE, "", "Please make sure that all cells are 11 digits or blank")

## How To Get Average Of First 3 Right Non Blank Cells

Apr 25, 2014

I am having a dilemma on getting the average for the first 3 non blank cells. This is how my data looks like :

excel average.jpg

I don't know any formula that will disregard the non blank cell and will get the average of the firs 3 non blank cells from the right.

## Average Next 5 Non Blank Values Of A Row

May 11, 2009

I would like cell B2 to show the average of the next 5 non blank values in row 2 (C2-Z2). The problem is there are varying blank cells (non data points) depending on each row. So i need the forumula to account for just the first 5 immediate non blank cells.

## Changing Criteria Code From Blank To Zero

Aug 29, 2012

The code below deletes all empty cells from column F starting from row 2 till last data cell in column A.

However what to change in it to do exactly the same except for empty cells, look out for "0" values...

Code:
Sub test()
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("F2:F" & LR).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub

## Formula For Getting Average Of Values Without Counting Zero Values In Range?

Dec 23, 2011

Is there a formula that would allow you to take the average of all values within a range but not count the zero values? I thought something like this might work but it's not. Neither one worked.

=AVERAGEIF(\$E\$4:\$E\$34,">0")
=AVERAGEIF(E4:E34,">0")

## Average Based On Last 7 Values (Non-blank / Zero)?

Aug 6, 2014

Book7.xlsx

The workbook is attached.

Columns B,C,D,E have the desired result in row 18.

What I want the formula to do is starting from row 13, go up and average the next 7 values that are not blank. If its easier, the starting point could be row 4 and I could adjust my data.

## How To Get Average Of First 5 Non-Blank Cells In A Column

Mar 24, 2014

I have a problem and I found a good explanation of something similar here:

[URL]

In the original posting the following formula solves the problem (attached) TestData.xlsx

B1: =AVERAGE(INDEX(B3:B100,MATCH(TRUE,B3:B100<>0,0)):INDEX(B3:B100,MATCH(TRUE,B3:B100<>0,0)+4))

What I would like to return is the average of the 1st 5 values, but what if a number of cells after the first value were also blank

## Take Average Eliminating Blank And Zero Cells

Mar 7, 2014

Can I take average in a row ignoring blank cells and zero values.