Is there a way in Excel to reference a cell range minus some cell? (As a function parameter) - excel-2007

Assume I have an Excel 2007 cell range of B3:B50. Is there any way to specify instead B3:B17+B19:B50, or maybe B3:B50-B18?
Several sources say that B3:B17,B19:B50 should work, but it doesn't work as a function parameter (for something like CORREL), since the comma is interpreted as separating parameters.

I tried with a named range (which can have multiple points in the definition) and for CORREL got #Value! returned, but SUM worked as expected.
you may have to test to see what functions will work

Related

SUMIFS returns 0 using dynamic criteria, with criteria range and sum range on another sheet

Anyone,
I've chatted with and called excel customer service with no luck. I used the formula builder (please see attached screenshot) to make sure each element of the formula is correct and returns the value for the criteria I'm trying to reference.
Everything is accurate, but it returns a value of 0. When I do the same thing in the actual sheet the data is stored in (and click a criteria cell within the criteria range) it returns the accurate value?! I'm not sure why it won't work on the other sheet. The values I am using to select are dynamic and change with a drop down. I have another, advanced, workbook (I did not create) that does the same thing and completes an even more complicated formula, but actually works so I'm not sure why this is returning a 0 value.
Photos and code/syntax: Dynamic Selection, Example 2 of it working, Example 1 of it working, Formula Builder, CountIFs, Advanced Spreadsheet working, VLOOKUP
=SUMIFS('GFEBS Pull'!Q:Q,'GFEBS Pull'!G:G,FMCOP!$C$20,'GFEBS Pull'!H:H,FMCOP!B23)
or:
=SUMIFS('GFEBS Pull'!Q:Q,'GFEBS Pull'!G:G,'FMCOP'!$C$20,'GFEBS Pull'!H:H,'FMCOP'!B23)
When I type ' around FMCOP sheet name, they disappear? I've also tried to lock the columns on the 'GFEBS Pull' sheet with no luck. Cell B23 is not locked because I'm going to copy the formula down to reference other cells. Any help is appreciated!
In this screenshot you can clearly see that both FMCOP!C20 ansd FMCOP!B23 have prefacing spaces; e.g. " HHC".
Since " HHC" will never match "HHC", fix the data returned from 'the lower table in the same screenshot'.
A Text-to-Columns, Fixed Width, Finish should do this. You could adjust the original formula like,
=SUMIFS('GFEBS Pull'!Q:Q, 'GFEBS Pull'!G:G, TRIM(FMCOP!$C$20), 'GFEBS Pull'!H:H, TRIM(FMCOP!B23))
I would caution against the latter 'bandaid' fix. Fix the original data; do not apply bandaids on-the-fly.

Evaluate a relative reference from VBA relative to a known cell

I'm using the trick described here - !A1 - to get the the range of cells up to and including the current one (typically for a Rows() function). This works great for day to day usage, and eliminates a lot of errors that I get when moving ranges around when I previously had to use an adjacent set of rows.
Unfortunately, my formulas need to be evaluatable from VBA. With __THISCELL__ as my !A1 cell, and the cell housing the formula as $Z$100 the following evaluates to an error:
Application.Evaluate(rngCell.formula)
And the following evaluates to $A$1:$Z$50
rngCell.Worksheet.Evaluate(rngCell.formula)
Obviously an approach is to replace __THISCELL__ with rngCell.Address(External:=True) prior to evaluation, but here's the kicker: I'd like to be able to execute my formula parser in a workbook which uses, say THIS_CELL, THISCELL or __THISCELL safely, and I'd also like to be able to safely execute my code in a workbook with a name like __NOT__THIS_CELL__.
All I need for this is a mechanism to evaluate relative references relative to a specific cell address - which since people do use R1C1 references in VBA a fair bit, I imagine must be around. However, I don't know it. Can anyone help?
NB: I like to avoid fiddling with ActiveCell, Selection, etc. where possible, since those smell like the excel equivalent of SendKeys - who knows what the user is doing when you access them. Even then, though, I'm not certain I'll get the right answer, because for the Worksheet.Evaluate approach, I'm not positioned in cell $A$1!
If I understand your question, I believe you're looking for the Range().Offset method.
Range().Offset(rOffset, cOffset) refers to a range that is rOffset lower and cOffset to the right of the given range (negative values for up and left are allowed). Also, .Offset can access and set all of the properties of the range, just like you would do with .Range.
The approach I've taken for the time being is implicit in the question: when a named range is detected, store the current selection and worksheet, select the one which we use as the evaluation context, and then use Evaluate. This seems to work, provided the cell being evaluated is inside the activesheet.
I don't like jumping the selection all over the place - feels dirty - but short of a more elegant solution, it does work.

MS Excel dynamic print area

I wish to create a dynamic Print_Area in Excel 2010 which will consist of two cell ranges.
For example the first cell range is A1:J50 and the second range is A100:J150. These should print out on two pages, ignoring the cells that come in between these two ranges.
The four cells shown in the above example ranges should be dynamic, and not hard coded as simple Print_Area ranges. Therefore in my worksheet I used cells AA1, AB1, AC1 and AD1 to store values "A1", "J50", "A100" and "J150" respectively.
(The cells AA1, AB1, AC1 and AD1 actually use formulas to determine what cell address will be used, but for this question lets just assume the values are set as above).
I then used the Name Manager and entered the following formula under Print_Area:
=INDIRECT(Sheet1!$AA$1):INDIRECT(Sheet1!$AB$1);INDIRECT(Sheet1!$AC$1):INDIRECT(Sheet1!$AD$1)
The result of this formula is exactly what I need, and it actually works the first time I print the ranges. However once I did that, Excel automatically substitutes the formula with the actual cell range that was calculated. So when I check the Print_Area in the Name Manager after printing once, it contains something like:
=Sheet1!$A$1:$J$50,Sheet1!$A$100:$J$150
Is there a way to prevent the Print_Area from converting my formula to calculated values, and instead using the formula every time I print? I would like to not use macros if at all possible (if not, I'll try macros too)
I tested this and it seemed to work.
Create a new name called Test and set its value to (Note that I used a comma rather than the semicolon you had. I have US language set)
=INDIRECT(Sheet1!$AA$1):INDIRECT(Sheet1!$AA$2),INDIRECT(Sheet1!$AA$3):INDIRECT(Sheet1!$AA$4)
Set your Print_Area name to
=TEST
Good luck!
EDIT
The above works for me, but it appears unnecessary. I just tried to replicate the problem, and was unable. When I have the Print_Area set to the formula with INDIRECT it does not replace after printing.
See this linked file. https://www.dropbox.com/s/pgm0iv19u6igdm5/Book1.xlsx

How can I create sheet-specific named ranges without using Indirect?

I've come up with a useful trick, where I create a named range that refers to the current worksheet, by using the following formula:
=RIGHT(CELL("filename",INDIRECT("A1")), LEN(CELL("filename",INDIRECT("A1"))) - FIND("]",CELL("filename",INDIRECT("A1"))))&T(NOW())
Where the INDIRECTs are there ONLY to stop Excel from Converting A1 --> Sheet1!A1. This works beautifully until I need to call evaluate on it from VBA (which does happen).
Can anyone tell me how either (1) to evaluate a name with this formula in VBA or (2) to get a sheet non-specific reference into the formula. I'd rather not use VBA, since it'll get evaluated ~12000 times, and that's likely to be slow, but if need be, it's probably ok. However, please bear in mind that the sheet it is calculated from is quite unlikely to be ActiveSheet, so the context for the Range() function in VBA is a little tricky - hence why I'm asking in the first place.
One possible approach: use a simple UDF which just returns the name of the sheet it's called from.
Eg:
Function SheetName()
SheetName = Application.Caller.Parent.Name
End Function

Excel VBA UDF that return value will override itself

Can I write a UDF in Excel VBA where the return value from the function will override the cell value from it is called from?
The function get information with a sql request. In this case it's only master data for example the item description. If the user will use this function in a worksheet in many cells excel will recalculate the cell value every time you change something. This has poor performance and normally it's only necessary to get the information one time and it hasn't to be updated in this case.
I thought to use application.caller.address method to get the address the function was called from but it seems it can't set the cell value for this address within the function.
So the return value of the function should override the original formula that run the function.
Is this possible
thanks for your help
No.
As you may have noticed Excel cells have multiple layers.
One is the "value". Another one the formula you can assign.
A funtions returns a value, therefore the return value only accesses this layer. So you cannot return a replacement for the formula cause it is on another layer.
A function differs from a sub in the return value, a sub does not return anything. Due to your behaviour of "one time usage" a sub will fit your need more than a function, because you dont want to return a value but to remove or replace certain content from cell (the formula).
However, this does not mean you cannot do this with a function - but still not with a return value. But you need to rewrite the whole formula on a data refresh if you would use such a function.
You may have missed a point that you make you laugh yourself I guess. Excel has such a thing natively. But it is not a function.
Copy your cells and paste them but use "values only".
Totally has the same effect.
Also in terms of recalculation... why not turn it off?
This would you not make to rewrite the function each time.