How do set a same string in a range of cells

There is a simple macro code in Excel to set the same string in a range…
Range(“F11:F40”).Value = “5905-6”
Simple one.
I wrote…
oRange = oSheet.getCellRangeByName(“F11:F40”)
oRange.String = “5905-6”
but I got the 423 errror
I think I will have to do a loop (for to next) to resolve this issue on Libreoffice?
Is that correct?

My example is for a special case…There are many cases…
Each case will fill the range with a specific number.
Does anyone know a simple macro code solution for this?

Select range, enter string, hit Alt+Enter.

1 Like

I´m doing a program for work coleagues. There are 30 lines in my report.

s = “5949-8”
oSheet=thiscomponent.getcurrentcontroller.activesheet
oRange = oSheet.getCellRangeByName(“F1:F28”)
a()  = oRange.getDataArray()
for i = 0 to uBound(a())
  r() = a(i)
  for c = 0 to uBound(r())
      r(c) = s
  next c
next i
oRange.setDataArray(a())

And the ultimative solution in python:

def wtf_do_i_write_nonsense():
    doc = XSCRIPTCONTEXT.getDocument()
    doc.CurrentSelection.Spreadsheet['F1:F28'].DataArray = [['5949-8']]*28

Disclaimer: no, I would not write in this cunky style in Practise

The task is simply too trivial to be chiseled into BASIC code.

just copy any String from a single cell by ctrl+c and paste it in any selected Range by ctrl+v

Take your Code from Excel, and write above into first line of Module:

Option VBASupport 1

Sub FillCells
Dim oRange as Object
Dim oSheet as Object
Dim i as Integer

oSheet=thiscomponent.getcurrentcontroller.activesheet
oRange = oSheet.getCellRangeByName(“F1:F28”)
For i = 1 to 28 'r
oSheet.getCellRangeByName(“F” & i).String=“5949-8”
Next i

End Sub

My God…a simple Range.Value turns into that on Libreoffice. Very complicated.

omg how stupid can it be, just copy &paste:

REM  *****  BASIC  *****
option VBASupport 1

sub fifty_nine_zero_five_minus_six
    Range("F11:F40").Value = "5905-6"
end sub

into your Module, and run it

1 Like

It works.
I wouldn’t want this…I want a pure Basic solution, but it worked.
Thanks for your attention.
it´s very sad that there is no solution on Basic Libreoffice.

There is at least one Variant, that you just had written, do you remember?

Did you mean “for to next” loop? But that solution has many codes. It´s not a beautiful solution.

Then use the one line of Python code…