Visual Basic Excel - Delete an array name

5

I'm here with some problems, I never moved in Visual Basic and was seeing if it helped me to make a listing that I have in Excel faster (Through Visual Basic Excel).

It's very simple, I just want to look in the array if you have a word that has less than 3 letters and if you have, delete the word or do replace for "" (which I think is to have nothing too) >

I had something like this, but it is not working, it returns:

  

Object required

My code:

  nome = Target(1, 1)
  nomesArray = Split(nome)
  Dim i As Integer
  i = 0
  While i < UBound(nomesArray, 1)
      If Len(nomesArray(i)) < 3 Then
          nomesArray.Value = Replace(nomesArray.Value, nomesArray(i), "")
      End If
      i = i + 1
  Wend

Can anyone help please?

    
asked by anonymous 29.07.2015 / 19:12

1 answer

3

Arrays in VBA (Visual Basic For Application ) are not objects, so they have no methods or attributes.

Therefore, Array.value can not be used, since the array has no attributes. Arrays in VBA are like Arrays in C and C ++.

Based on what you need to do, I've modified your code, see below:

nome = Target(1, 1)
nomesArray = Split(nome)
Dim i As Integer
i = 0
While i < UBound(nomesArray, 1)
  If Len(nomesArray(i)) < 3 Then
      nomesArray(i) = ""
  End If
  i = i + 1
Wend

Note that the only modification was to change the way you assign the empty value to the position of the vector that has less than 3 positions.

Finally, the array will remain the same size, but with positions that have value="".

    
30.07.2015 / 13:10