INDIRECT If Statments keeps giving #REF - vba

I'm trying to change an if statement to an indirect one as the current one that works keeps changing from C27 to #REF! when I delete Row 27 in the Tracker sheet.
=IF('Tracker Sheet'!C27="","",'Tracker Sheet'!C27)
This is the old if statement that works
=IF(INDIRECT('Tracker Sheet'!C27)="","",INDIRECT('Tracker Sheet'!C27))
This is the if statement that I try to convert but gives me #REF!
Any help would be greatly appreciated

Use index:
=IF(INDEX('Tracker Sheet'!C:C,27)="","",INDEX('Tracker Sheet'!C:C,27))
As long as you use the cell address directly when it is deleted it will return #REF as you are deleting the reference.
This will always look at what is the current 27th row in column C.

Related

Excel Indirect command returns #value

Using COUNTIF to count the number of times the value "HW or SW" shows up in a column. I am not sure how many rows of data I will end up with so I want to make that a variable, using INDIRECT. This formula returns a #VALUE error and I cannot figure out why: =COUNTIF('Daily_Data_Dump'!$G$2:INDIRECT("$G"&AB3),"HW_or_SW") Where the value in cell "AB3" is 5000. In my mind is should be the equivalent of =COUNTIF('Daily_Data_Dump'!$G$2:$G5000,"HW_or_SW"). Thanks for any help.
"In my mind is should be the equivalent of =COUNTIF('Daily_Data_Dump'!$G$2:$G5000,"HW_or_SW")."
That is correct, the problem is something else. The adress is wrong, try:
=COUNTIF('Daily_Data_Dump'!$G$2:INDIRECT("Daily_Data_Dump!$G"&AB3),"HW_or_SW")

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.

Error 1004 when using =AND(ISERROR) formula in macro

I'm recording a macro to automate some Excel reports and have encountered the following bug whenever I try and run an iserror(search) formula:
Run-time error '1004': Application-defined or object-defined error
I have two lists. The formula iterates through the first list and compares the values with those of the second list, hiding any matching values.
The formula in Excel is like this only with a wider criteria range:
=AND(ISERROR(SEARCH($B$3212,B2)),ISERROR(SEARCH($B$3213,B2)))
It works perfectly when I insert the formula directly into the spreadsheet cell however I get an error when I record and later run the macro using the same formula.
EDIT 2
I got the formula insertion to work through the macro but now I cannot filter the data as before, even when I do it manually without the macro.
Below is a link to a picture giving an example of the type of lookup I'm trying to achieve, previously it worked perfectly and removed all the rows which contained a string from the 'to remove list' now I cannot get it to filter at all. I've tried removing the macro after saving in notepad in case the file had become corrupted but it still does not filter as before. What could be causing this?
This is how the lookup works
Cell [A13] would contain the aforementioned ISERROR formula in this example.
This formula doesn't translate well to VBA in its current form. You should use the VBA Instr function instead of the worksheet function Search.
Function FindSubstring() As Boolean
Dim rngFindText As Range
Dim rngWithinText As Range
Set rngFindText = Sheet1.Range("B3212")
Set rngWithinText = Sheet1.Range("B2")
FindSubstring = InStr(rngWithinText, rngFindText)
End Function
Sub foobar()
Debug.Print FindSubstring
End Sub
You are asking Excel a question to tell you to find the contents of $B$3212 in B2 and to find if again.
Usually the SEARCH is used to find the contents of one thing in another, by using it again the AND statement you are asking it again ... and for what?
Hence the question does not make sense.
What I think you might be asking if just once and if there is an error meaning it did not find it there in this instance for it to return 0.
=IF(ISERROR(SEARCH($B$3212,B2)),0,SEARCH($B$3212,B2))
I figured this one out, the original 1004 error was caused by vba only partially recording the formula, the solution involved simply going into the debugger to find which line hadn't been translated correctly and editing that line. I then had to edit the formula so as to be able to filter out values acording to my criteria and ended up with a formula closer to this:
=AND(ISERROR(SEARCH("Value1",B2)), ISERROR(SEARCH("Value2",B2)))

add listrow to empty listobject

With some VBA code in Excel I have an odd problem when adding a row to an empty listobject. Does anyone know what is happening or how to fix it? Here is the problem:
First I delete the contents of a listobject (table), using:
AListObject.DataBodyRange.Delete
Then I have a loop that iteratively adds a row and fills it with data. I add the row by using:
AListObject.ListRows.Add
Here is the odd behavior. First, the code deletes the listobject's data:
AListObject.DataBodyRange.Delete
The immediate window shows AListObject.ListRows.Count equals 0, so all rows are deleted. Then I add a row:
AListObject.ListRows.Add (first iteration)
Immediate window shows AListObject.ListRows.Count equals 2, so the Add method created two rows, instead of one. Furthermore, the data written to row 1 is lost. Row 1 of the listobject (table) displays empty cells.
For the remaining iterations (2 to n) of the loop the ListRows.Add method works fine, creating only one row. Writing data to those rows (2 to n) works fine as well.
Why does the first Add method, called when the listobject is empty, create two rows, and why can't I write to row 1? This code previously worked fine, and it works fine in old back-up versions of my workbook. Does anyone know why this is odd behavior occurs?
Thanks.
JNevill, thanks for responding. With some more persistence I solved the problem. A filter was set, and calling AListObject.DataBodyRange.Delete when the filter was set caused the problem. The solution was to remove all filters prior to calling the delete method, as follows:
AListobject.AutoFilter.ShowAllData
AListObjct.DataBodyRange.Delete
Thanks again for responding, and if I have an occasion to to post again, I'll follow your advice and post the actual code.

#Value! error with =(A1+A2)

I'm trying to add multiple cells with the formula =(A1+A2+A3...etc)
Which works, but if all the cells are empty then I get a #Value!
PLEASE NOTE:
Yes I am aware the proper way to add cell values is with =SUM(A1:A3)
However the cells I'm adding together each have their own functions to get their numbers, and the =SUM function won't add them together.
So! Is there a way I can make =(A1+A2+A3...etc) not give me a #Value! error in the cell that's supposed to total them if ALL the cells (A1,A2,etc) are empty? (as in, the cell with the total will just be blank)
Yes I know this is overly complicated. I'm working with that I've got.
EDIT
I might have figured out my problem. My 'false' statement in the function of the cells that were being added is "" in order to make the cell not have a 0 in it when empty. When it tries to add those cells together, if they all read "" and none are a number that's when I get the #Value! error. Not sure yet what I'm going to do about that...
EDIT 2
Yup. Problem was caused by having a non-numerical value as my false statement. Didn't want a bunch of zeros everywhere, but oh well I guess.
I tried both Excel 2007 and Calc 3.4.1, and neither one of these generated the #Value! that you mention. I am thinking that perhaps your source cells' equations are producing a value that is causing this to error out.
For example, if one of the cells has a String value, then this will be the result. This can be detected with the TYPE() function. for example:
=( IF(TYPE(A1)=1;A1;0) + IF(TYPE(A1)=1;B1;0) + ...)
this will make sure that you are actually adding numbers before the addition takes place.
edit
See: http://www.techonthenet.com/excel/formulas/type.php
for details on TYPE()