Getting a “Inadmissible value or data type. Index out of defined range.” on the variable nnnCols when copying the contents of a sheet into a 2D array of 1000 rows and 300 columns)
Intention is to load a entire sheet contents into RAM to run faster a long set of checks then dump it back on file at the end (otherwise the checks run for hours).
This example should just fill the first column with “-” so that filtering later on does not skip rows.
Dim oooDoc As Object
Dim oooSheet As Object
Dim oooRange As Object
Dim aaaData() As Variant
Dim nnnRows As Long
Dim nnnCols As Long
Dim z As Long
Dim y As Long
Dim temp_cell As Variant
Dim temp_string As String
oooDoc = ThisComponent
oooSheet = oooDoc.CurrentController.ActiveSheet
oooRange = oooSheet.getCellRangeByPosition(0,0, 300, 1000) ' Range is A1 to KI100001
aaaData = oooRange.getDataArray() ' Read all data into RAM array
nnnRows = UBound(aaaData, 1)
nnnCols = UBound(aaaData, 2)
MsgBox "Found " & nnnRows + 1 & " rows and " & nnnCols + 1 & " columns of data."
For z = LBound(aaaData, 1) To UBound(aaaData, 1)
For y = LBound(aaaData, 2) To UBound(aaaData, 2)
temp_cell = aaaData(z, y)
temp_string = CStr(temp_cell)
If temp_string = "" Then
aaaData(z, y) = "_"
End If
Next y
Next z
oooRange.setDataArray(aaaData) ' dump the whole modified array back to the file
The sheet is not empty, contains both strings and values across multiple cells towards the start.
Ran the code by Google AI and it said it runs on his 7.6 version of Libre Office. Many of the fancy code is its.
So I am stumped as to the problem. It seems to not load as 2D array for some reason…
How do I solve this?
