Página 1 de 1

Validação de Dados

Enviado: 08 Fev 2018 às 12:55
por GladstoneD
Ola, pessoal do VBA

É o seguinte. Eu preciso criar uma maneira de verificar se as textbox estão vazias e as que estiverem, receber o valor 0. Criei uma sub cheio de IFs, mas acredito que exista uma maneira de otimizar a execução. Podem me ajudar? Desde já agradeço
Código: Selecionar todos
Sub ValidaVazios()

With Me

If .TextBox1.Value = "" Then
.TextBox1.Value = 0 * 1
End If

If .TextBox2.Value = "" Then
.TextBox2.Value = 0 * 1
End If

If .TextBox3.Value = "" Then
.TextBox3.Value = 0 * 1
End If

If .TextBox4.Value = "" Then
.TextBox4.Value = 0 * 1
End If

If .TextBox5.Value = "" Then
.TextBox5.Value = 0 * 1
End If

If .TextBox6.Value = "" Then
.TextBox6.Value = 0 * 1
End If

If .TextBox7.Value = "" Then
.TextBox7.Value = 0 * 1
End If

If .TextBox8.Value = "" Then
.TextBox8.Value = 0 * 1
End If

If .TextBox9.Value = "" Then
.TextBox9.Value = 0 * 1
End If

If .TextBox10.Value = "" Then
.TextBox10.Value = 0 * 1
End If

If .TextBox11.Value = "" Then
.TextBox11.Value = 0 * 1
End If

If .TextBox12.Value = "" Then
.TextBox12.Value = 0 * 1
End If

End Sub

Validação de Dados

Enviado: 08 Fev 2018 às 13:19
por JCabral
Código: Selecionar todos
Sub ValidaVazios()

Dim i As Integer

For i = 1 To 12
      If Controls("TextBox" & i).Value ="" Then
             Controls("TextBox" & i).Value = 0*1
      End If
Next i

End Sub
Será qq coisa como isto?

Re: Validação de Dados

Enviado: 09 Fev 2018 às 10:07
por GladstoneD
JCabral escreveu:
Código: Selecionar todos
Sub ValidaVazios()

Dim i As Integer

For i = 1 To 12
      If Controls("TextBox" & i).Value ="" Then
             Controls("TextBox" & i).Value = 0*1
      End If
Next i

End Sub
Será qq coisa como isto?
É exatamente isso. Obrigado. Eu imaginei que precisaria de usar o For..Next, mas não conhecia esse Controls. Obrigado!!!