Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array Size Returned by Split Function - Excel VBA

Tags:

excel

vba

Here is what I have done so far.

Sub MP_division()

Worksheets(3).Activate    
Dim last_cell As Integer    
Dim platforms() As String    
Dim arr_size As Integer  

platforms = Split(Cells(2, 47), ", ")    
last_cell = Mid(Range("A1048576").End(xlUp).Address, 4)    
arr_size = len(platforms) // is there something like this?    
For x = 1 To last_cell    
    For y = 1 To arr_size 
        //do something        
    Next        
Next   
End Sub

My question is, how may I get the array size(arr_size) that is returned by the split function, so that I could use in my for loop? Thank you.

like image 579
Kentot Avatar asked Feb 14 '14 08:02

Kentot


People also ask

What does split function return in VBA?

Description. The Microsoft Excel SPLIT function will split a string into substrings based on a delimiter. The result is returned as an array of substrings. The SPLIT function is a built-in function in Excel that is categorized as a String/Text Function. It can be used as a VBA function (VBA) in Excel.

How do I find the size of an array in Excel VBA?

VBA Code to get the length of Array (one-dimensional array):Press Alt+F8 to popup macro window. Select ” oneDimArrayLength” and Click Run button. Compute Number of Rows, Number of Columns using UBound and LBound function. Multiply by noOfRow and noOfCol variable to get Number of elements in multi-dimensional array.

How do I fix type mismatch error in VBA?

Step 1: Write the subprocedure for VBA Type Mismatch. Step 2: Again assign a new variable, let's say “A” as Byte data type. Let's understand the Byte Data type here. Byte can only store the numerical value from 0 to 255.


1 Answers

VBA LBound and UBound return the first and the last array position, so the correct answer is:

size = UBound(myArray) - LBound(myArray) + 1
like image 163
farope Avatar answered Sep 20 '22 15:09

farope