Array Size Returned by Split Function - Excel VBA
Consider abound using LBound and Ubound:
Sub MP_division() Dim last_cell As Long Dim platforms() As String Dim x As Long, y As Integer With ThisWorkbook.Worksheets(3) platforms = Split(.Cells(2, 47), ", ") last_cell = .Cells(.Rows.Count, "A").End(xlUp).Row For x = 1 To last_cell For y = LBound(platforms) To UBound(platforms) 'do something Next Next End WithEnd Sub
Btw, Split always returns zero-based array (starts from 0
, but not from 1
). Thats why I recomend you to use both, Ubound and Lbound.
One more thing, I've changed Dim last_cell As Integer
to Dim last_cell As Long
, since max value of Integer
only 32767
and if the last row would be greater than 32767
, you would get an error with Integer
.
And avoid using Select/Active statements (it's about Worksheets(3).Activate
)