Reference external file with ^ in name - vba

I am trying to pull data from external workbooks into a main workbook. I have done this before several times and it always works with the below formula.
='FolderPath[FileName]WorksheetName'!CellReference
The above formula still works for me now on many workbooks. However I have thousands of workbooks with a ^ in the name. Example Workbook1^01012017.
When I get to these types of workbooks I get the below error:
"The syntax of this name isn't correct." and the text in the cell gets highlighted until the first ^.
If I type in = in my original workbook
Open the workbook I want to reference
Select the cell I need
Hit Enter
The link works. If I copy that text exactly and change the reference from cell A1 to A2 in another cell, I get the same error. The problem seems to be that it's reading the ^ as a symbol instead of a text. Is there any other way to get this to work? I have tried using a indirect function, but those don't work when the external workbook is closed.
Any suggestions?

Related

openpyxl: cells do not evaluate

I have this simple python script:
from openpyxl import Workbook
book = Workbook()
sheet = book.active
sheet["A1"]=3
sheet["A2"]=4
sheet["A3"]="=SUM(A1:A2)"
book.save("k_test.xlsx")
When I open the excel sheet A3 is empty (not calculated). If have to click on the cell and press enter - then the value appears. How can I force excel to calculate the values?
In case anyone runs into the same problem. There were two issues:
as I was starting from a non English Excel version, I forgot to translate one command to English. So it showed up right lateron in Excel, but there had been an internal error in between that kept it from evaluating it.
I had references to an Excel tab that did not exist at the time of inserting the formula. This also leads to the problem that it cannot be evaluated. I had to add the referenced tab, before I could add the formula referring to it.

VB.net copy and paste excel cell to elsewhere in the workbook

So i am currently using Visual Studio to create a application that takes info out of an excel sheet and then does some calculations on the data and then pushes back to excel.
This bit i have managed to do but the bit i am struggling on is using a 'Parameters' sheet. I want to be able to enter a formula into a cell in one sheet of the workbook and then paste that formula into another sheet but to have it updating,e.g. as the cells go down the formula changes like it would in excel. I used a manual work around by hard coding the formula and then having variable as the row number, however i want to be able to just change the formula in the excel sheet and then when the code runs it applies to the rest.
Currently i have tried saving the cell value/text into a variable and then making the new cells equal that variable, however this then applies the same identical formula to the whole of the column(All required rows).
What i am currently trying to do is paste the variable into the top row and then copy and paste that cell down to the last one,
I have tried making the variable a formula but it evaluates the formula before it is equal to the variable and therefore just sets all the new cells to the formula answer, so i changed the cell to be text instead which then meant the formula did appear in the new cell however it was the identical formula for all cells.
The copy code works as below
bjExcel.cells(rown, colval) = param1
objExcel.cells(rown, colval).copy
This is working fine
But when i use the below the paste won't work
Do Until rown = 10
objExcel.cells(rown, colval).copy
rown = rown + 1
objExcel.cells(rown, colval).paste
Paste is not a recognized with the error:
System.MissingMemberException: 'Public member 'Paste' on type
'ApplicationClass' not found.'
Could be you need to use PasteSpecial instead?
https://learn.microsoft.com/en-us/office/vba/api/excel.range.pastespecial
Depends on what you're using to interop with excel.
shWorkSheet.Range("C7:C7").Copy()
shWorkSheet.Range("V7:V7").PasteSpecial(Excel.XlPasteType.xlPasteAll)

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

How to link files in excel with a text in the path changing dynamically?

I have a file which needs to fetch data accordingly every week.
Let us say the formula to get data in a cell is
=\T:\Datafile\weekdata\2015\Week01\[Summary.xlsx]Sales'!D4
I have a cell in the sheet C3 which changes every week accordingly.It will change to week02 next week and i wish the path to change too..to
=\T:\Datafile\weekdata\2015\Week02\[Summary.xlsx]Sales'!D4"
I tried doing a concatenation to make the path dynamic
="\T:\Datafile\weekdata\2015\"&C3&"\[Summary.xlsx]Sales'!D4"
but it doesn't seem to work out.I checked evaluate formula and it resolves C3 to Week02 but the value doesn't come in the cell.In stead just the below text
\T:\Datafile\weekdata\2015\Week02\[Summary.xlsx]Sales'!D4
appears in the cell instead of any number.
Let me know where am i going wrong and how to resolve it.
Try =INDIRECT():
=INDIRECT("\T:\Datafile\weekdata\2015\"&C3&"[Summary.xlsx]Sales'!D4")
This function does exactly what you are trying to do, takes a built string and makes it a cell reference.
The problem with =INDIRECT() is that it only works if the source workbook is open:
If the source workbook is not open, INDIRECT returns the #REF! error value.
(That quote is from https://support.office.com/en-sg/article/INDIRECT-function-21f8bcfc-b174-4a50-9dc6-4dfb5b3361cd)
By googling "excel convert text to formula" I found this SO Q&A: How to turn a string formula into a "real" formula
If you don't like the VBA solution, I had success with
iDevlop's =EVALUATE() solution.

Excel Reference External Sheet

An excel question for you gurus. I've tried searching high and low and haven't come up with an effective solution.
I'm trying to create a formula that will lookup a value in an external sheet. I'm using the SUMPRODUCT formula and it works perfectly. Formula is below:
=SUMPRODUCT(--('File\Path\[file.xlsx]SheetName!$D$1:$D$1000=$B3), --('File\Path\[file.xlsx]SheetName'!$O$1:$O$1000=$A3), 'File\Path\[file.xlsx]SheetName'!$Q$1:$Q$1000)
The issue I'm running into, however, is that the source file is updated every day. Although the workbook name stays the same, the sheet name changes. A random string gets assigned to the source sheet name each time it is updated. As such SheetName becomes SheetName ase341.
Is there a way to have the formula read the external sheet number instead of the name? I want the formula to update regardless of the sheet name. If there's no way to read the sheet position is there a way to change the sheet name via a formula in an external workbook?
Usage Example
I have a workbook (analysis) and it pulls data from another workbook (source). Source is updated every day with new data. The data in Source is updated by downloading a report from the internet and saving over the old source file. As such, the file name stays the same but whatever is inside the file is always different (including the sheet name). There is always only ever one sheet in the Source with the same number of columns, always in the same position.
There is a really neat way to refer to a block of cells in an external workbook in which the sheetname or even the block address may vary. Say we have:
=SUM('C:\Users\James\Desktop\[Book1.xlsx]Sheet1'!$B$2:$B$9)
however the sheetname may vary. First assign a Defined Name to the block in Book1 (say XXX)
Then we can use:
=SUM('C:\Users\James\Desktop\Book1.xlsx'!XXX)
It does not matter if the sheetname changes, the Defined Name will change with it!
Your issue would be most efficiently solved with VBA, but if you're just getting started this might not be the best route.
You can get the sheetname or filename with just a formula, though:
http://www.ozgrid.com/VBA/return-sheet-name.htm