Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
Por GladstoneD
Posts
#30103
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
Avatar do usuário
Por JCabral
Avatar
#30104
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?
Você não está autorizado a ver ou baixar esse anexo.
Por GladstoneD
Posts
#30123
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!!!
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord