On 07/04/2011 01:29 PM, James wrote:
I want to put an 'x' in Calc cells based on whether another cell's
date (totalincoming) is larger than a different cell's value.
I started this macro but is there an easier way?
How do I set a cell's value?
Well, off hand, i would say that you cannot depending on how the macro
is called. If the macro is called as a function from in the sheet, then
that function may not directly change the value of a cell in the same
sheet that caused the function to be called. if the macro is called
based on some other event (or if the cell that you desire to change is
on another sheet), then it is fine.
REM ***** BASIC *****
' put an 'x' in cells where totalincoming (06:41:45) is greater or
equal to flatrateincoming (06:36)
Sub Main( totalincoming As Date, flatrateincoming as Date )
Option Explicit
dim cellcontents as string
If totalincoming >= flatrateincoming Then
cellcontents = "x"
End If
' set current cell's value
This part is a bit tricky. First of all, you must be able to get the
cell of interest. You probably want to do something like:
Dim oCell
oCell = ThisComponent.getSheets().getByName("Sheet1").getCellByPosition(2,4)
Now, what do you want to set? A string
oCell.setString("X")
A numeric value
oCell.setValue(3.141592654)
End Sub
If the values are known to be held in specific cells, then just use a
formula in the cell of interest. You can also write your own function,
that simply returns the value of interest, and call that function
(macro) from the cell of interest.
--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info: http://www.pitonyak.org/oo.php
--
-----------------------------------------------------------------
To unsubscribe send email to [email protected]
For additional commands send email to [email protected]
with Subject: help