I'm trying to call a function to process some data in an array, I will be duplicating this for lots of different reasons, so just want to get the basic foundations right and I'm getting errors with data types. I've simplified my code to try and get it going from the ground up but still can't find the cause.
Sub VBA_Split_Print()
Dim last_row As Long
last_row = Cells(Rows.Count, 1).End(xlUp).Row
Range("J2:AE90000").ClearContents
For J = 2 To last_row
Dim arr() As String
arr = Split(Worksheets("Raw").Cells(J, 9).Value, ",")
Call ElectiveAdd(arr)
Next J
End Sub
Function ElectiveAdd(ByRef arr() As String)
Dim arrLength As Integer
arrLength = UBound(arr, 1) - LBound(arr, 1)
Dim x As Integer
x = 0
For i = 24 To (arrLength + 24)
Worksheets("Raw").Cells(J, i).Value = arr(x)
x = x + 1
Next i
End Function
When I'm trying to run this I am getting an Run-Time Error '1004' Application-Defined or Object-Defined Error message.
So revised code due to feedback and I feel that J is another issue so I have excluded it, thanks for pointing out the error though!
Sub VBA_Split_Print()
Dim last_row As Long
last_row = Cells(Rows.Count, 1).End(xlUp).row
Range("J2:AE90000").ClearContents
Dim arr() As String
arr = Split(Worksheets("Raw").Cells(2, 9).Value, ",")
Call ElectiveAdd(arr)
End Sub
Function ElectiveAdd(ByRef arr() As String)
Dim arrLength As Integer
arrLength = UBound(arr, 1) - LBound(arr, 1)
Dim x As Integer
x = 0
For i = 24 To (arrLength + 24) + 1
Worksheets("Raw").Cells(2, i).Value = arr(x)
x = x + 1
Next i
End Function
Now I am getting a different error message of subscript out of range, cell 2,9 = "
JinWorksheets("Raw").Cells(J, i).Value = arr(x)= 0.J? What do you expectJto equal inWorksheets("Raw").Cells(J, i).Value = arr(x)? What happens if you addOption Explicitto the very top of the module? Does it flagJas an undeclared variable?+ 1fromFor i = 24 To (arrLength + 24) + 1