Sub ParTimeFill()
'Declare variables
Dim oDoc As Object
Dim oSheet As Object
Dim pRange As Object
Dim sInput As String
Dim sInput2 As String
Dim oRange As Object
Dim oCell As Object
Dim iRow As Integer
Dim iCol As Integer
Dim foundCells() As String
Dim foundCount As Integer
Dim arrData As Variant
Dim i as Long
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
'start find and replace
'start
oRange = oSheet.getCellRangeByName("O1:O300")
ReDim inputArray(2, 0, 0)
For iRow = 0 To oRange.Rows.Count - 1
For iCol = 0 To oRange.Columns.Count - 1
oCell = oRange.getCellByPosition(iCol, iRow)
If oCell.String = "PAR TIME HERE" Then
ReDim Preserve foundCells(foundCount)
foundCells(foundCount) = oCell.AbsoluteName
Dim targetCellR As Object
Dim targetCellU As Object
targetCellR = oSheet.getCellByPosition(oCell.CellAddress.Column + 5, oCell.CellAddress.Row)
targetCellU = oSheet.getCellByPosition(oCell.CellAddress.Column + 8, oCell.CellAddress.Row)
DIm strR As String
Dim strU As String
Dim strCombined As String
strR = targetCellR.String
strU = targetCellU.String
strCombined = strR & strU
'Declare an array to store the data
arrData = Array("flem2 OPEN LR,26.47436", "flem4U OPEN LR,49.33333", "flem3F OPEN G2,37.97581", "flem4UM OPEN G2,48.24603", "flem3 OPEN G2,41.4", "flemOPEN G3,50.875", "flem4U OPEN G1,54.20968", "flem3U OPEN G2,50.46154", "flem3 OPEN LR,37.93023", "flem3 OPEN G3,39.11905", "flemQlty G3,51.90789", "flemOPEN G2,52.81481", "flem3 OPEN G1,43.91875", "flem3UFM OPEN G1,52.03125", "flem4UM OPEN G3,47.86154", "flemOPEN LR,49.28017", "flem2 OPEN G3,25.82353", "flemBM96,46.58333", "flemBM90,42.71333", "flem3 OPEN,40.40076", "flem3U OPEN G1,55.43233", "flem34FM BM70,35.91071", "flem2F OPEN G3,27.15152", "flem3UFM OPEN,43.275", "flem3F OPEN LR,36.83333", "flem4U BM90,45.72222", "flem3U OPEN LR,48.22535", "flemBM80,41.93617", "flem3F OPEN G1,39.30435", "flem3F OPEN G3,39.84524", "flem3 Qlty LR,39.92", "flem3U BM80,42", "flem3 BM70,35.00758", "flem3UFM BM70,36.09524", "flem3U BM84,42.46622", "flem3U BM70,36.42333", "flem3U OPEN,47.18333", "flem2F OPEN,25.33333", "flem3U BM78,41.35", "flemBM70,37.35065", "flem4U BM70,37.79787", "flem2 OPEN,29.00658", "flem3U BM100,47.41667", "flem3UFM BM78,41.33333", "flem3U MDN,24.80952", "flem3U CL1,29.72917", "flem3U NMW,35.29762", "flem3UFM BM64,30.9", "flem3 BM64,31.86842", "flem4U BM64,30.60714", "flemBM84,43.52632", "flem3UFM OPEN G3,46.3", "flem3CG OPEN G3,43.28571", "flemOPEN G1,54.51923", "flemQlty,47.91837", "flemOPEN,42.8913", "flem3F OPEN,34.5", "flem3 Qlty,41.75943", "flem2 OPEN G2,32.80769", "flem4UM OPEN,46.33333", "flemFM BM78,38.82558", "flemBM78,39.95455", "flemBM100,45.4375", "flem3F BM78,38.95", "flem2U BM90,38.6875", "flem2UFM BM78,40.83333", "flem3U Qlty,46.66", "flemFM BM90,45.05", "flem2 Qlty,27.25", "flem3UFM Qlty,44.8", "flem2 Qlty LR,34", "flemQlty LR,50.14815", "flem4UM BM84,43.90909", "flem3CG OPEN LR,39.22727", "flem4U Qlty G2,52.65", "flem4UM BM70,30.77273", "flem3CG OPEN,34", "flem3U BM64,32", "flemNMW,38.1", "flem4UM BM78,41.8")
'Check if the combined string exists in the array
For i = LBound(arrData) To UBound(arrData)
If InStr(arrData(i), strCombined) > 0 Then
'If it does exist, post the value paired with the string in the array
oCell.String = Replace(Mid(arrData(i), InStr(arrData(i), strCombined) + Len(strCombined)), ",", "")
End If
Next i
End If
Next iCol
Next iRow
End Sub
After experimenting with this I think my arrays are far too big and have to split them up, the code works now with smaller contents in the array. I think it must have something to do with memory limitations because an error message I received was it couldn’t find “alScope”. “alScope” is nothing but it is a part of the word “GlobalScope” which I use to call the library at the beginning of the main function. One array I estimate has around 7300 elements.
I have a laptop with 8GB of RAM which would be enough because it never maxxed out so I think I just pushed the software beyond its limits maybe?
EDIT: This code has the shortened array in it.