I'm using EPPLUS to build custom Excel spread sheets. One functionality that I'm missing is to change the name of a cell. Is this somehow possible with EPPLUS? If not are there any other ways of doing it?
Suppose that book is your workbook and sheet is your worksheet. Let try this code snippet
var cell = sheet.Cells["C2"]; // Cell or Range you want to name
sheet.Names.Add("The_Name_Here", cell);
The name will be added to sheet. If you want to access the name in the whole workbook, try:
var cell = sheet.Cells["C2"]; // Cell or Range you want to name
book.Names.Add("The_Name_Here", cell);
Depend on your need the scope of the name can be sheet.Names or book.Names.
I don't know how to modify an existing name but sure that 1 cell/range may have multiple names.
Related
I have a workbook - lets call it Book1
Book1 contains 5 worksheets; Sheet1, Sheet1A, Sheet2, Sheet2A, Summary
Within the Summary worksheet there is a table which contains summary of the data held in the other 4 worksheet.
The first column in the table contains rows naming each of the 4 worksheets; Sheet1, Sheet1A, Sheet2, Sheet2A.
Using the excel HYPERLINK function I have created links in each of these rows so as to navigate directly to each particular worksheet, as follows:
=HYPERLINK("[Book1.xlsx]Sheet1!A1", "Sheet1")
=HYPERLINK("[Book1.xlsx]Sheet1A!A1", "Sheet1A")
=HYPERLINK("[Book1.xlsx]Sheet2!A1", "Sheet2")
=HYPERLINK("[Book1.xlsx]Sheet2A!A1", "Sheet2A")
However, only two out of the four hyperlinks work. The two which do not work are those which end with 'A'; Sheet1A and Sheet2A
All worksheets have been spelt correctly and I have experiment with the format to see whether changing to text or general made any difference, but it did not.
Please could could someone shed some light on why I am facing an error with Sheet1A and Sheet2A - my thoughts are that it is something to do with there being a letter after the number?
Thank you for your time.
If they're in the same workbook, then try adding the # & '
=HYPERLINK("#'"&"Sheet1A'!A1", "Sheet1A")
=HYPERLINK("#'"&"Sheet2A'!A1", "Sheet2A")
I'm building a dynamic validation list, the missing ingredient is the following
I need to populate a cell (A1) with the contents of the last modified cell in a workbook.
I dont know the column/row/sheet of the cell i want to retrieve its content. So basically it is the last entry, and it can be anywhere in the workbook
Any chance of doing that?
Assuming that data will be stored in sheet named lastModifiedRange
function onEdit(e) {
const sheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName('lastModifiedRange')
sheet.getRange('A1').setValue(e.value);
sheet.getRange('A2').setValue(e.source.getActiveSheet().getName());
sheet.getRange('A3').setValue(e.source.getActiveRange().getA1Notation());
sheet.getRange('A4').setValue(e.oldValue);
}
edit : if you want to write it in the same sheet
function onEdit(e) {
const sheet=e.source.getActiveSheet()
sheet.getRange('A1').setValue(e.value);
}
I may going up the wrong tree with this.
I have the following formula, that will replace the * with the range of sheets in the workbook, and SUM the values in cell B2 on each of the sheets:
=(SUM('*'!B2)/J2)/100
This works fine, however the formula doesn't retain the '*', it replaces it with the actual range, eg:
=(SUM('Period 1:Period 4'!B2)/J2)/100
So, is it possible to either:
Retain the '*' so that the formula doesn't update, and therefore remains dynamic should I add a new tab.
Add a reference into the reference. The first sheet will always be 'Period 1', however the end sheet will change from month to month, and will be 'Period x', where x is the value in cell J2. Is it possible to reference J2 within =(SUM('Period 1:Period 5'!B2)/J2)/100? =(SUM('Period 1:Period [J2]'!B2)/J2)/100 or something similar?
The only way I know to do this is to create a 'sheet sandwich' with a 'Start' and 'End' sheet then the range is =SUM('Start:End'!B2). New sheets obviously have to be inserted between these to be included.
Note:not my solution, credit belongs to SUM across multiple sheets with variable sheet name question.
If you want to get data from a different workbook's cell you do something like this:
='FilePath\[FileName]Worksheet'!ColumnRow
When you want to create a hyperlink to another workbook you do something like this:
=HYPERLINK("[FilePath\FileName]Worksheet!ColumnRow", FriendlyName)
Now how do you get FriendlyName to be a reference to the external cell ='FilePath\[FileName]Worksheet'!ColumnRow?
Example:
I have two Excel documents.
C:\Fish\FTypes.xlsx
Has a worksheet named Summary
C:\Birds\BTypes.xlsx
In FTypes.xlsx I have cell B:36 with some data in it. In BTypes.xlsx I want the cell G:55 to be a hyperlink to FTypes.xlsx B:36 cell. Also, as the "FirendlyName" for BTypes.xlsx G:55 cell, I want it to be the data from FTypes.xlsx B:36 cell. How would I go about doing that? Here is my attempt at it:
=HYPERLINK("[C:\Fish\FTypes.xlsx]Summary!B36",'C:\Fish\[FTypes.xlsx]Summary!B36')
That one says "We found a problem with this formula. ..." I also tried:
=HYPERLINK("[C:\Fish\FTypes.xlsx]Summary!B36","'C:\Fish\[FTypes.xlsx]Summary!B36'")
That on just puts 'C:\Fish[FTypes.xlsx]Summary!B36' in the cell.
This works for me (note at my closing ' after Summary):
=HYPERLINK('C:\Fish\[FTypes.xlsx]Summary'!B36,'C:\Fish\[FTypes.xlsx]Summary'!B36)
Lets say
sheet3.name = "d"
Is there a way I could put in a cell on sheet2 the formula =sum(sheet3!b:b) where sheet3 is being substituted with the actual sheet3 name?
I can only get =sum('d'!b:b) to work so far.
I could use VBA for this probably but I'm curious how to do this in a cell so I don't have to run a macro each time.
If you can use a UDF User Defined Function that will return the sheet name
Function SHEETNAME(number As Long) As String
SHEETNAME = Sheets(number).Name
End Function
then a formula like
=SUM(INDIRECT(SHEETNAME(3) &"!B:B"))
will return the sum from column B on sheet 3.
SHEETNAME(number) returns the sheet name of the number which is index.
So Sheet(1) returns Sheet1, etc
Use below formula anywhere in the sheet to get the sheet name - the sheet must have a filename for this to work:
=REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")
You can either reference that cell using Indirect:
=SUM(Indirect("'"&A1&"'!B:B"))
or, if you don't want to have a second cell, you can combine the two formulas into one:
=SUM(INDIRECT("'"&REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")&"'!B:B"))
For anyone not concerned with the order of the sheets, the post by Biff here on mrexcel.com works well.
In Excel 2013, go to the Formulas tab in the ribbon and make a defined name:
Name: SheetNames
Refers to: =GET.WORKBOOK(1)&T(NOW())
Then use a formula like this example:
=INDIRECT("'"&INDEX(MID(SheetNames,FIND("]",SheetNames)+1,255),A3)&"'!A1")
where A3 refers to the index number in a cell in the current sheet, and A1 refers to the location of the value to be retrieved from the other sheet. I.e., in the current sheet, if A3 = 2, then the formula will point to cell A1 in the second sheet of the workbook. I just use a column of index numbers in my current sheet, then drag this formula down and it fills in values from all of my other sheets.
You will need to save as a macro-enabled file (.xlsm).
I'm not sure if this is a good idea but it's the first one I could think of.
I would add additional function to your VBA project which will return actual name of your Sheet3:
Function Sheet3Name()
Sheet3Name = Sheet3.Name
End Function
Next, when you create sum formula of column B:B in Excel cell you need to do it in this way:
=SUM(INDIRECT(Sheet3Name()&"!A:A"))