OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

formula using cell coordinates

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc
View previous topic :: View next topic  
Author Message
abecker
General User
General User


Joined: 01 Feb 2006
Posts: 6

PostPosted: Thu Mar 23, 2006 1:48 pm    Post subject: formula using cell coordinates Reply with quote

I am trying to covert a Lotus 123 spreadsheet to Calc and I can not seem to find a way to convert this 123 formula.
the formula uses cell corrdinates instead of the cell address. The main reason for using this is to get to different sheets without having to know the sheet name.
An example of the 123 formula is:
@@(@COORD(2,5,88,8))

In this example you are referring to the cell in the 2nd sheet, 5 columns over and 88 rows down. The 8 at the end is a 123 notation selecting the type of reference you\ want( absolute, varialble or mixed reference).

you can use the above reference in a formula and it is treated the same as a normal cell address.

Is there anything similar in Calc or a way of accomplishing the same thing.
Any help would be greatly appreciated
thanks
Back to top
View user's profile Send private message
denmarks
OOo Enthusiast
OOo Enthusiast


Joined: 01 Mar 2006
Posts: 125
Location: Chico, CA

PostPosted: Thu Mar 23, 2006 3:05 pm    Post subject: Reply with quote

OOo uses the format sheet1.A1 to refer to a sheet and cell. A sheet name can be absolute or relative and will change names if affected by inserted sheets or sheet renames.

COORD(2,5,88,Cool could be initially set up as sheet2.B88 and will change automatically if sheet names change. $ in front of a sheet name has the same absolute or relative effect as on cells.

You can always use meaningfull sheet names and cell names such as year2006.jantotal.
_________________
Dennis Marks
Back to top
View user's profile Send private message Visit poster's website
Dale
Super User
Super User


Joined: 21 Feb 2005
Posts: 1440
Location: Australia

PostPosted: Thu Mar 23, 2006 3:13 pm    Post subject: Reply with quote

Try the ADDRESS and INDIRECT functions. Read Help and get back to us if you need more info.
_________________
Dale
To err is human, but to destroy your slippers in the process takes a real son of a bitch: Me!

OOo documentation from the source
http://documentation.openoffice.org
Guides, FAQ, How Tos
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3318

PostPosted: Thu Mar 23, 2006 10:46 pm    Post subject: Reply with quote

The short answer to your question, I believe, is that there appears to be no way in Calc to refer to a Sheet without using the sheet name. It is possible, however, to leave the names to the default, which is Sheet1, Sheet2, etc. Evil or Very Mad
Back to top
View user's profile Send private message
RickRandom
Super User
Super User


Joined: 27 Jan 2006
Posts: 1082
Location: UK

PostPosted: Sat Mar 25, 2006 4:09 am    Post subject: Reply with quote

Another function that might be relevant here is OFFSET, which will get the contents of a cell that is offset a number of rows and columns from another cell.
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10065
Location: Germany

PostPosted: Sat Mar 25, 2006 6:41 am    Post subject: Reply with quote

Quote:
@@(@COORD(2,5,88,Cool)

In this example you are referring to the cell in the 2nd sheet, 5 columns over and 88 rows down. The 8 at the end is a 123 notation selecting the type of reference you\ want( absolute, varialble or mixed reference).

It would be interesting what the "8" means to Lotus 1-2-3.
Assuming some sheets "Sheet1", "Sheet2","Sheet3". And you want to refer to Sheet2, 5 columns to the right, 88 rows down from the used cell sheet1.A1:
$Sheet2.F89
Next sheet, 5 columns to the right, 88 rows down from the used cell sheet1.A1:
Sheet2.F89
When you rename sheet2 refs will be adjusted. When you copy this ref to sheet2.B2 it will refer to Sheet3.G90.
Always this cell: $Sheet2.$F$89
Calculating a cell position:
INDEX(Sheet2.$A$1:$IV$65536;88;5) or INDEX(Sheet2.$A$1:$IV$65536;88;5)
or INDEX(Sheet2.$A$1:$IV$65536;ROW()+87;COLUMN()+4)
or OFFSET(Sheet2.$A$1;88;5) or OFFSET(Sheet2.$A$1;ROW()+87;COLUMN()+4)
Unlike row/col-positions we can't refer to calculated sheet-positions, but we can use a relative ref to a sheet-name, which will be adjusted when the sheet gets another name. When you move the sheet to another position a relative reference to this sheet will be preserved.
Back to top
View user's profile Send private message
abecker
General User
General User


Joined: 01 Feb 2006
Posts: 6

PostPosted: Fri Mar 31, 2006 8:41 am    Post subject: Reply with quote

Thanks for the responses but I do not think those solutions will work. The project I am working on is a template. Each customer would have a separate file and we update the template every year. So the sheet namesare the date of the update - thats why I need a formula that does not need the sheet name. The next thing is a summary page that compares the last 4 years. That is why a relative reference will not work--because the comparision page only wants the last 4 sheets and those will change every year because we are adding a new sheet each year. That is why the Lotus formula worked well because it worked on cell coordinates a more absolute reference and sheet names did not matter.
The work around I have been trying is to creat a macro to discover the last 4 sheet names and store them as a variable. Then have the macro fill in the formulas; but I been having problems getting a variable to work in a formula. Hopefully someone can help. What I got so far is:

Sub DiscoverSheetName

dim oSheetOne as Object
dim oSheetTwo as Object
dim oSheetThree as Object
dim oSheetFour as Object

oSheetOne=ThisComponent.Sheets().getByIndex(0)
FirstSheet=osheetOne.Name()
oSheetTwo=ThisComponent.Sheets().getByIndex(1)
SecondSheet=osheetTwo.Name()
oSheetThree=ThisComponent.Sheets().getByIndex(2)
ThirdSheet=osheetThree.Name()
oSheetFour=ThisComponent.Sheets().getByIndex(3)
FourthSheet=osheetFour.Name()

Print "1st sheet name is " & FirstSheet
Print "2nd sheet name is " & SecondSheet
Print "3rd sheet name is " & ThirdSheet
Print "4th sheet name is " & FourthSheet

oSheetOne=ThisComponent.Sheets().getByIndex(0)
osheetone.getCellRangeByName("a1").setFormula("=SecondSheet.c4")

Ignore the print commands they are just my way of testing. The last line is the problem.
I have assigned the sheet names to a variable but I can not use it in a formula. Anyone have any idea or I going about in the wrong way.
Any assistance would be greatly appreciated
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10065
Location: Germany

PostPosted: Fri Mar 31, 2006 9:02 am    Post subject: Reply with quote

How about this short function which can be used in a cell:
Retunes #VALUE on wrong index.
Code:

Function getSheetNameByIndex(n)
i = cint(n)-1
REM passed index and Sheets.Count is base 1, we use base 0 here
If (i>=0)AND(i<ThisComponent.Sheets.Count) then
  getSheetNameByIndex = ThisComponent.Sheets.getByIndex(i).getName
end if
End Function

In a spreadsheet
=getSheetNameByIndex(Sheets())
gives last sheet name to be used with
=INDIRECT(ADDRESS(8;88;1;getSheetNameByIndex(SHEETS())))
gets ref to cell (8;88 ) in last sheet.
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10065
Location: Germany

PostPosted: Fri Mar 31, 2006 9:13 am    Post subject: Reply with quote

What I would try at the end of period (possibly with a short macro):
named ref thisSheet
=MID(CELL("FILENAME";IV1);FIND("#$";CELL("FILENAME";IV1))+2;256)
returnes name of this sheet:
Select all sheets
Select next free column of all sheets
=thisSheet
Copy, Paste special values
Put everything in a single list
Optional: Make this table a readonly data-source
Do aggregation with pivot-tables by customer, year, month, quarter, you name it.
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3318

PostPosted: Fri Mar 31, 2006 9:03 pm    Post subject: Reply with quote

Quote:
osheetone.getCellRangeByName("a1").setFormula("=SecondSheet.c4")

You are using the variable name as part of the formula, which does not compute. You need to extract the value of the variable for your formula string, something like:
Code:
sFormula = "=" & SecondSheet & ".c4"
osheetone.getCellRangeByName("a1").setFormula( sFormula )
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10065
Location: Germany

PostPosted: Sat Apr 01, 2006 5:55 am    Post subject: Reply with quote

noranthon wrote:
Quote:
osheetone.getCellRangeByName("a1").setFormula("=SecondSheet.c4")

You are using the variable name as part of the formula, which does not compute. You need to extract the value of the variable for your formula string, something like:
Code:
sFormula = "=" & SecondSheet & ".c4"
osheetone.getCellRangeByName("a1").setFormula( sFormula )

If it works for him then his sheet is named as the variable.
@abecker,
I think, my set of functions, posted here http://www.oooforum.org/forum/viewtopic.phtml?t=32909 can provide another solution. I added a new function CELL_VALUE() as well as getCellValue() from my basic library:
Background: A basic-function only gets a number or text from a spreadsheet-function passing a cell-ref. If you want to get some info about the referenced cell itself, you have to use an addressing scheme, similar to the Lotus-notation, you mentioned. In this case =CELL_VALUE(1;1;1) provides just a clumsy detour to get the same result as =$Sheet1.$A$1, but using another addressing scheme. The set of sheet-functions ("CELL_*()")use another function getSheetCell() which gets a cell-object by the addressing-scheme:
Sheet-Index (1-256) or Sheet-Name
Row-index (1 to row-count)
Column-index (1-256)
My posting in the snippets-forum provides some examples how to implement relative and mixed addressing.
I added getCellValue(oCell). This is nessesary because the OOo-API can be used with some strictly typed programming-languages. So you can not simply assign a cell-value to a variable. getSheetCell() returnes a value of basic-type "Variant" after analysing what the real type of the cell is.
The functions return basic "NULL" on errors, caused by wrong address-parameters. In a spreadsheet they appear as #VALUE.
getCellValue also returnes #VALUE from error-cells while returning "" from empty cells.
Unfortunately hard recalc is required (Ctrl+Shigt+F9) in order to update this kind of cell-functions
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group