3
I’m trying to make a simple code using the split
, but some mistakes are occurring that I’m not able to solve.. no if
with asterisk VBA informs me that the subscript
this out of range..
Sub Getinstrument()
Dim instrument As String
Dim splitinstrument() As String
Dim i As Integer
Dim removespax As Integer
Dim tam As Integer
removespax = -1
'Set instrument = Range(ActiveCell.Row, B)
instrument = Range("E3")
splitinstrument() = Split(instrument)
tam = Len(instrument) - 1
For i = 0 To tam
**If splitinstrument(i) <> "" And "x" Then
removespax = removespax + 1
splitinstrument(removespax) = splitinstrument(i)
End If
Next
ReDim Preserve splitinstrument(removespax)
MsgBox splitinstrument()
End Sub
Really weird code... You should look at the size of the array itself to go through it; instead, you are orienting yourself by the size of the range
instrument
. You need to debug and identify the content ofsplitinstrument
. This array may be empty.– Caffé
i made the following modifications to the code
– MOISES
eu fiz as seguintes modificacoes no codigo instrument = Range("E3")
splitinstrument() = Split(instrument)
 
For i = LBound(splitinstrument) To UBound(splitinstrument)
 If splitinstrument(i) <> "" Then
 removespax = removespax + 1
 splitinstrument(removespax) = splitinstrument(i) End If Next I will debug the code and VBA keeps giving error in splitinstrument type 'type Mismatch'. I tried to use the mid function to separate my string but continued with the same problem.
– MOISES
Please update your question with the new code and inform the line that the error occurs.
– Caffé