Jack Ray wrote:
>
> I can't figure this out. I need a Macro that will fill a cell with a
> random integral number, between 2 and 7, when a key is hit, not, as
> random works normally, whenever the spreadsheet refreshes.
> Can anyone show me how?
> Jack
>
>
I'm guessing this does what you want. It just inserts the formula, then
converts it to a value.
' * * * * * script follows
Sub randValue27
'Inserts a random value between 2 and 7 in the selected cell of a
spreadsheet using setFormula
'rather than FunctionAccess. Set to work ONLY if a single cell is selected.
Dim oCell as Object, sFormula as String
oCell = ThisComponent.CurrentSelection
If NOT oCell.supportsService( "com.sun.star.sheet.SheetCell" ) Then : Exit
Sub : End If
sFormula = "=RANDBETWEEN(2;7)" : oCell.setFormula( sFormula)
oCell.setDataArray( oCell.getDataArray )
End Sub
' * * * * * script has ended
You could, perhaps more usefully, use script which performs a hard
recalculation.
' * * * * * script follows
Sub hardRecalc
' Performs a hard recalculation of the spreadsheet - does NOT count as a
modification
Dim oDoc as Object : oDoc = ThisComponent
If NOT oDoc.SupportsService ( "com.sun.star.sheet.SpreadsheetDocument" )
Then
Exit Sub : End If
oDoc.calculateAll()
End Sub
' * * * * * script has ended
Beware the effects of copying and pasting from an email to the Calc Basic
editor. Your email client may convert single lines to multiple lines. I
can upload a text file if you have problems.
--
View this message in context:
http://www.nabble.com/Macro-question-in-Calc-tf3574343.html#a9989422
Sent from the openoffice - users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]