"Application-defined or object-defined error" when inserting row - excel

I've completed parsed my code and found that the error is in this line of code, but I have no idea why:
Range(c).Resize(tmp_n).EntireRow.Insert
Where c is defined as string that looks like : "A3" or some other row and tmp_n is simply an integer.

Based on the error message and lack of surrounding code I would say that your tmp_n variable either doesn't have a value or is declared as a String.

Related

Why am I getting a value error in excel while using the ifs function?

=IFS(SEARCH("C*",A9),"Cake",SEARCH("K*",A9),"Cookies",SEARCH("B*",A9),"Bread & Bun",SEARCH("Y*",A9),"Pastry")
It works for the first criteria and returns "cake" but won't work for the others. I keep getting a #VALUE error.
Can help please??
SEARCH isn't a Boolean-valued function. It doesn't return FALSE if the string isn't found -- it returns a #VALUE! error which isn't coerced to FALSE.
What you could do is wrap everything like SEARCH("C*",A9) with ISNUMBER(): ISNUMBER(SEARCH("C*",A9)) since Excel can tell that #VALUE! isn't a number.

How to remove text from a field

In the SO Invoice report, I add a link from ARTran to FSAppointment. This is done in order to include FSappointment.LongDescr in the report. A request, is to remove the text 'Internal Notes' PLUS all text following the string. I notice a red error message printed in the report output, in the cases where 'Internal Notes' string is not included in LongDescr. I tried several permutations but have not found a resolution.
Here is my formula
=IIf(InStr([FSAppointment.DescriptionAsPlainText],'Internal Notes')>0,
Left( [FSAppointment.DescriptionAsPlainText], InStr([FSAppointment.DescriptionAsPlainText],'Internal Notes') )
,[FSAppointment.DescriptionAsPlainText])
Note that I created a non-bound field DescriptionAsPlainText, in order to apply pretty formatting, for LongDescr field.
Here is the error message:
An error has occurred while the Left(Identifier(FSAppointment.DescriptionAsPlainText), InStr(Identifier(FSAppointment.DescriptionAsPlainText), Const(Internal Notes))) function was being executed:
'Length cannot be less than zero.
Parameter name: length'
I think your code fails if the value of [FSAppointment.DescriptionAsPlainText] is null. Add an IIF([FSAppointment.DescriptionAsPlainText]=null, clause around your existing code to exit in case of null.

invalid input syntax for type numeric: " "

I'm getting this message in Redshift: invalid input syntax for type numeric: " " , even after trying to implement the advice found in SO.
I am trying to convert text to number.
In my inner join, I try to make sure that the text being processed is first converted to null when there is an empty string, like so:
nullif(trim(atl.original_pricev::text),'') as original_price
... I noticed from a related post on coalesce that you have to convert the value to text before you can try and nullif it.
Then in the outer join, I test to see that there's a limited set of acceptable characters and if this test is met I try to do the to_number conversion:
,case
when regexp_instr(trim(atl.original_price),'[^0-9.$,]')=0
then to_number(atl.original_price,'FM999999999D00')
else null
end as original_price2
At this point I get the above error and unfortunately I can't see the details in datagrip to get the offending value.
So my questions are:
I notice that there is an empty space in my error message:
invalid input syntax for type numeric: " " . Does this error have the exact same meaning as
invalid input syntax for type numeric:'' which is what I see in similar posts??
Of course: what am I doing wrong?
Thanks!
It's hard to know for sure without some data and the complete code to try and reproduce the example, but as some have mentioned in the comments the most likely cause is the to_number() function you are using.
In the earlier code fragment you are converting original_price to text (string) and then substituting an empty string ('') if the value is NULL. Calling the to_number() function on an empty string will give you the error described.
Without the full SQL statement it's not clear why you're putting the nullif() function around the original_price in the "inner join" or how whether the CASE statement is really in an outer join clause or one of the columns returned by the query. However you could perhaps alter the nullif() to substitute a value that can be converted to a number e.g. '0.00' instead of ''.
Sorry I couldn't share real data. I spent the weekend testing small sets to try and trap the error. I found that the error was caused by the input string having no numbers, which is permitted by my regex filter:
when regexp_instr(trim(atl.original_price),'[^0-9.$,]') .
I wrongly expected that a non numeric string like "$" would evaluate to NULL and then the to_number function would = NULL . But from experimenting it seems that it needs at least one number somewhere in the string. Otherwise it reduces the string argument to an empty string prior to running the to_number formatting and chokes.
For example select to_number(trim('$1'::text),'FM999999999999D00') will evaluate to 1 but select to_number(trim('$A'::text),'FM999999999999D00') will throw the empty string error.
My fix was to add an additional regex to my initial filter:
and regexp_instr(atl.original_price2,'[0-9]')>0 .
This ensures that at least one number will be in the string and after that the empty string error went away.
Hope my learning experience helps someone else.

Conversion error If value = "" Then

I'm getting a error I can't quite explain I have a Excel list I want to load into memory, to see if the next row is still a relative row I check if the cell has a value by doing If value = "" Then but the value is 1012738 and it gives me a unhandled exception...
I can't quite understand why the code is giving a error, the cell value is formatted just like all previous cells that were checked. But here a error is thrown.
Maybe i'm just not seeing it, and someone can explain?
You should check the value each time.
Dim o As Object = oSheet.Range(xxx).Value
If (o IsNot Nothing) Then
Select Case o.GetType
Case GetType(Double)
' do work here
Case GetType(Integer)
' do work here
...
End Select
Else
...
End If
Your image isn't showing up for me.
Most exceptions in excel are datatype related. Most likely, you either have a NULL or a string that looks like an integer to the human eye. You can blindly try using trim(), int() or str() etc as needed to make sure you're actually testing an integer or matching a string if thats what you are about or you can test them in a programmatic method.
First, the programmatic method of testing ... isEmpty or isNull are needed to ensure the cell is good ...
if isEmpty(value) Then
<do something>
This will most likely catch the error which is causing the message. If empty is failing, try testing with isNull. One means the cell is empty, the other means that it wasn't initialize (rarely an issue in excel, but if using vba code it can happen).
Also ... your if statement is setup in a less than optimal... used <> in place of if then + else ...
Your code ...
If value = "" Then
General formula when you want to test that something is not something else, use the not equals ...
if value <> "value" Then
"some operation"

Method 'Range' of object '_Global' failed error when referencing Named Ranges

I got a Method 'Range' of object '_Global' failed error when I'm trying to reference a workbook scope Named Range. I've referenced other Named ranges with the same code, and they all work fine. Only this particular range throws an error.
The function for the named range is this
=OFFSET(INDIRECT(ADDRESS(91,MATCH(Calculation!$G$89,Calculation!$C$90:$S$90,0),,,"Calculation")),,-2,1,5)
I couldn't figure out what's the issue with this, could anyone help me out please? Thanks!
This is the line that throws the error
Set rngVs = Range("'CAR Dashboard.xlsm'!PenLineSelected1Y")
You may want to try:
Set rngVs = Names("PenLineSelected").RefersToRange
If that still fails, then one likely cause of error:
You have -2 for the cols argument in your Offset function. If the Address function returns an address in columns A or B, this will raise a #REF! error.
I put each part of the formula in its own cell just to see where it is failing. Observe that a match in the 3rd column of C90:S90 will not cause an error:
But if I change the search term to "World" (which will be found in column B), the Offset function will fail.

Resources