Hi,
I have this vba code:
I know it's not very elegant - got my stripes in COBOL - but anyway the problem is around the 4th time I access the array I get the error:
"This array is fixed or temporarily locked". Googling I find it hard to understand the problem or the solution, so was thinking is there an alternative like ArrayList?
Appreciate any advice how I can get round this problem.
Thanks
I have this vba code:
Code:
Sub addImageURL()
Dim Arr() As String
Dim name As Variant
Dim caption As String
Dim totSpecies, totImages As Long
Dim i, notFoundCnt, existCnt As Integer
Dim speciesName As Variant
notFoundCnt = 0
existCnt = 0
totSpecies = Sheets(2).Range("A" & Rows.Count).End(xlUp).Row
totImages = Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To totSpecies
imageName = Sheets(2).Cells(i, 2).Value
Set found = Sheets(1).Range("E2:E" & totImages).Find(what:=imageName)
If found Is Nothing Then
GoTo nexti
End If
Sheets(2).Cells(i, 8).Value = found.Offset(, -2).Value
Sheets(2).Cells(i, 9).Value = found.Offset(, -1).Value
caption = "<a href=""https://florapalaestina-ethnobotany.org/?plant=" & Sheets(2).Cells(i, 1).Value
caption = caption & "/"" target=""_blank"">" & vbCrLf & "<b>" & Sheets(2).Cells(i, 11).Value & "</b>" & vbCrLf
If Len(Sheets(2).Cells(i, 4).Value) > 3 Then
caption = caption & " <ul>"
Arr = Split(Sheets(2).Cells(i, 4).Value, ",", 3)
nameCnt = 0
For Each name In Arr
nameCnt = nameCnt + 1
caption = caption & "<li>" & name & "</li>"
If nameCnt > 2 Then
caption = caption & "</ul>" & vbCrLf
GoTo arb
End If
Next
caption = caption & "</ul>" & vbCrLf
End If
arb:
If Len(Sheets(2).Cells(i, 6).Value) > 3 Then
caption = caption & " <ul>"
ReDim Arr(1 To 12) As String
Arr = Split(Sheets(2).Cells(i, 6).Value, ",", 3)
nameCnt = 0
For Each name In Arr
nameCnt = nameCnt + 1
caption = caption & "<li>" & name & "</li>"
If nameCnt > 2 Then
caption = caption & "</ul>" & vbCrLf
GoTo heb
End If
Next
caption = caption & "</ul>" & vbCrLf
End If
heb:
If Len(Sheets(2).Cells(i, 5).Value) > 3 Then
caption = caption & " <ul>"
ReDim Arr(1 To 12) As String
Arr = Split(Sheets(2).Cells(i, 5).Value, ",", 3) 'error 10 here
nameCnt = 0
For Each name In Arr ' error occurs here on 2nd iteration
nameCnt = nameCnt + 1
caption = caption & "<li>" & name & "</li>"
If nameCnt > 2 Then
caption = caption & "</ul>" & vbCrLf
GoTo endNames
End If
Next
caption = caption & "</ul>" & vbCrLf
End If
endNames:
ReDim Arr(10)
caption = caption & "</a>"
Debug.Print "Caption" & caption
Sheets(2).Cells(i, 10).Value = caption
nexti:
Next i
End Sub
"This array is fixed or temporarily locked". Googling I find it hard to understand the problem or the solution, so was thinking is there an alternative like ArrayList?
Appreciate any advice how I can get round this problem.
Thanks