All reference values in Excel sheet becomes '!#REF! when refering values from another sheet - vba

One of our excel program stops working and I am trying to figure out why.
In the program, there are multiple sheets. The one cannot calculate value is called "Piston", and the reason is that all reference values from another sheet called "General Input" fail to refer.
The following are some failed cells in "Piston" sheets:
='General Input'!#REF!*(0.0063/0.0111)*EXP(-1*0.0214*$C$9)
='General Input'!#REF!*EXP(-1*0.0214*$C$9)
=AB5*(AD5+AC5*DG5)/(AD5+AB5*DG5)/'General Input'!#REF!
=$C$8*0.0000032/('General Input'!#REF!*Piston!$C$4*Piston!N10*(2*$C$6/1000)^2*('General Input'!$C$16/1000)^2)
=((BV9^3)*(BQ9^2)/DJ9/8+(BW9^3)*(BR9^2)/DK9/4+(BX9^3)*(BS9^2)/AE9/4+(BY9^3)*(BT9^2)/DL9/4+(BZ9^3)*(BU9^2)/DM9/8)/12/'General Input'!#REF!*$G$26/(1000000)^3
Apparantly all different values in "General Input" fail suddenly at the same time. I am not the one who wrote the code, and I don't use it as well. I am just asked to fix the bug.
But I just want to ask, is there any reason that suddenly make all referred value fail from a sheet?
Sorry if the information I provided is too vague.

!#REF! used to be a cell reference - e.g. $G$9
='General Input'!#REF!*(0.0063/0.0111)*EXP(-1*0.0214*$C$9)
However, such link/reference to G9 doesn't exist anymore - e.g. G9 was deleted.
The best hope is that you saved different version of such Excel. If yes, go back to an older version and copy those formula.
Good luck.

Related

Sheet not found via codename

I'm running across and error that appears sporadically. Essentially, a master .xlsm file is used by multiple people to populate data for aggregation. I then use another .xlsm file with macros to pull the data and aggregate it into a single source file.
The code generally works quite well, with one exception:
'define range based on count'
Set rngItemRange = SourceWb.Sheets("Quality").Range(Cells(3, i), Cells((intItemCount + 2), i))
'write concatenated range'
targetwb.Sheets("Raw Data").Cells(pintDest_row, pintCol).Value = concatRange(rngItemRange)
It cannot find the tab "Quality" on some work books (but not all). Okay, maybe someone renamed the tab? checked that, thats not true. One thing that works as a work around: on the open source workbook, when debug throws an error, if i manually click the quality tab, then resume the macro, it will continue.
I also said, okay, well maybe there's some weird character recognition issue, so I started to refer to the sheet by the codename as shown in the vba editor. I experience the same behaviors.
This affects maybe 50% of the workbooks, and I cant find any root cause. I have similar code elsewhere, for different sheets, but this is the only one where i define a range to pass into a function using the "set" command. Again, this only happens sometimes on some workbooks, and i can continue to execute when i manually click on the tab i'm pulling data from.
I'll also add, there is only one workbook open with this sheet name, at any given time, so i dont think it's choking trying to figure which sheet is relevant. Plus sourceWb is a set variable.
Does someone have any clue whats going on? anything to try? solutions? help!
(Forgive any typos, I'm working on a broken thumb right now.)

Excel Data type/validation - pulling in the correct data

I have a macro. Code part is fairly simple:
Sub Test()
Worksheet.Range("A1").Value = ws.Range("A2").Value2
End sub
Working just fine for ~6,000 lines. One line is causing problems, formatted like so:
12345A0
Now, there are quite a few other lines like this. They process just fine. This cell, Excel thinks it's a Number, and flags a warning that "Hey this is a number". It then only pulls in
12345
and truncates the rest of the cell, seeming to figure "Oh, it's a number, I'm fixing it." But I need the entire ID. What is a simple way to get Excel to think "Hang on, I need to get the actual cell contents" - Is there an easy way to do this? (Programatically - this part is part of code that cycles through different sheets and workbooks given to us, and a manual fix will not work)
Edit: Copying and pasting the cell produces 12345 - the ending is truncated.
Edit 2: Selecting the data inside of the cell and hitting enter changes the cell to 12345. What's going on Excel? Excel 2010 since this might be relevant
Edit 3: Application.ErrorCheckingOptions.NumberAsText = False doesn't do anything besides remove the flag - Excel is still convinced that it's a number in the cell, and not a string. Nevermind what data type we give it.

How to get defined table name in Excel?

I have an excel file with several sheets with assigned to them alliances. One of value on one sheet is calculating by using code below:
VLOOKUP(D10; lst_table_col; 4;00);
It doesn't matter that VLOOKUP function do, that matters is what exactly sheet behind lst_table_col. The problem is that this excel file doesn't contain any lst_table_col sheet. I'm looking for any solution: by just mouse, vba - whatever.
I believe my question is very easy, but this situation confuse me.
You must have a table called lst_table_col
Because if it was a direct reference to an Excel Range, you would see something like this in the formula :
SheetName!R1C1:R10C4
or
A1:D10
so check in Formula Tabs -> Name Manager to find it! ;)
Here is the link for the tutorial provided by #Rocketq : https://support.office.com/en-ca/article/Define-and-use-names-in-formulas-4d0f13ac-53b7-422e-afd2-abd7ff379c64#bmmanage_names_by_using_the_name_manage

Excel VBA: Resetting spreadsheet count

I have a excel VBA macro that dynamically generates and deletes spreadsheets based on user input. However, when I open the VBA IDE, it seems that although I am naming my spreadsheets in the subs that create/delete them, the overall count is still increasing.
For example, depending on how far into execution my program is, under the "Microsoft Excel Objects" folder in my current project, the spreadsheets in the current workbook could look something like
Sheet101(Sheet3)
Sheet103(Sheet2)
Sheet104(Sheet1)
Or
Sheet81(Inputs)
Sheet83(Date Adjustment Interpolation)
Sheet84(Pricing)
Sheet85(Comparison)
No matter if I delete the rest of them and add one, it still picks up where the last highest one left off.
I don't know how many times this macro will be run and I'd feel a lot better about putting it out there if I could reset this annoying tally on the number of spreadsheets that have ever been generated, since I don't know for sure where excel will cut me off. Plus it's just annoying.
My Question:
I would like to know how to alter that spreadsheet number, or at least what the relevant object is for doing so.
Thanks!
Thanks to #dijkay s suggestion on code names, I've found some code to accomplish this.
ThisWorkbook.VBProject.VBComponents("Sheet1").name = "test"
Will change the code name of Sheet1 to test, so in the Excel Objects folder, it will appear as test(Sheet1) for example.
This option, however, requires messing around with some trust/security settings in each individual excel client running the macro, which is unsuitable for my purposes, unfortunately. You can also change the value manually by changing the (Name) property directly in the IDE through the properties window.
here are some ideas you can try...
Sheets(x).Name = "Sheet" & x
or (assuming in this example, 'Sheet3' doesn't already exist:
Set Sheet3 = sheets.Add
Sheet3.name = "Sheet3"
This is more cleanup than re-setting
cheers,
Micéal

Inconsistent recognition of ranges (No errors thrown)

This is code from Excel 2010. All of the code resides within the workbook itself. Information is gathered using internal forms and the code is run.
I have code that retrieves data from a spreadsheet and populates an object with that data. The row number is dynamic as it is dependent on the form input. The column is by the header, not the column number. The following code works perfectly but for two anomalies:
cTank.RowForTankSpecs = rNum
cTank.MP = .Cells(rNum, Range("MP").Column).Value
cTank.Form = .Cells(rNum, Range("formName").Column).Value
cTank.TankProcess = .Cells(rNum, Range("Process").Column).Value
cTank.Location = .Cells(rNum, Range("Location").Column).Value
cTank.TankName = .Cells(rNum, Range("Tanks").Column).Value
cTank.tankID = .Cells(rNum, Range("TankID").Column).Value
First:
The cTank.TankName is retrieving information from a column named "Tanks". That column does not exist. The actual column header is "Tank". But, it is retrieving the correct information. If I change the name to what it really is (Tank), it does not work.
Second:
When the cTank.TankID line is executed, I get the following error on the Range("TankID"):
Runtime Error 1004: Method 'Range' of object '_Global' failed
This one has the appropriate header (column header), but it is not recognizing the range.
I have tried simple things such as changing the order of the code, but it doesn't help. As earlier stated, the other lines work. Later in the program, information is gathered in the same manner but using another worksheet from the same workbook, and none of them are working. I've double checked that strings are strings and integers are integers, etc. I've double checked the column headers match the range names. Nothing seems to jump out at me.
I would appreciate any input you may have on the situation.
Thanks in advance.
Steve
Ok. Being pretty sure my code was correct, I went to the spreadsheet itself. For some reason it was recognizing only certain columns and it was recognizing one of them incorrectly. So I started highlighting the columns that worked and also the columns that didn't. What I noticed was that on the columns that were being recognized, that column header was displayed where the cell location is normally displayed whereas on the columns that were not being recognized, the cell location (i.e. A1, A2, etc.) for the header was being displayed and not the header title itself. The incorrect label was showing up for one of them. As it turns out, the mislabeled column was one that I had used for a form dropdown menu. So, I checked the name manager, and the ones that were working were listed. So anyway, using the name manager, I added named ranges using the headers. Now, when I select the columns, the column header(named range) appears in that window and now, the code works.
Thanks guys for your input. I really appreciate it.
Two things you can do:
Do not use use Range, but as it seems you are using names, use Names("Yourname").Referstorange.
OR
Make sure your names are set up correctly using the Name Manager in Data Ribbon.