Visual Basic Programming in Excel

2

Using Excel's Visual Basic mode, I'm creating a customer master record form. It has a button called " new ". In this button it would add a value to the Code field that is in the excel worksheet. However, when I test it it displays the following message:

  

Run-time error '9': Subscript out of range

And when I click debug, it points to the following line of code as 'wrong':

Do Until Sheets("CLIENTES").Cells(linha, 1) = ""

What should I do to resolve this problem?

    
asked by anonymous 17.04.2014 / 20:58

1 answer

2

What was missing was you referencing what you wanted from the cells, it is not being able to understand the error.

The correct would be to use the following:

Do Until Sheets("CLIENTES").Cells(linha, 1).Value = ""
'faz alguma coisa
Loop

So you will be informing that you want to get the value of the Cell (line, 1) that is in the Worksheet ("Clients")

    
17.04.2014 / 21:44