Renvoie de valeur par TextBox

XC2ONE

XLDnaute Junior
Bonjour à tous,

Comment faire pour qu'une TextBox non remplie dans un formulaire par un utilisateur ne renvoie pas une valeur 'espace' car dans la base de données, quant on fait un NBVAL sur la zone, les cellules non remplies dans le text Box sont comptées comme une valeur, il faut faire SUPPR à chaque fois.....

Merci à vous.....
 

_Thierry

XLDnaute Barbatruc
Repose en paix
Bonsoir XC2One, le Forum

Un simple Test comme ceci dans le bouton de Validation de ton UserForm (avant l'envoie des données sur Feuille)

If TextBox1 = '' Then Exit Sub

Mais Logiquement selon ce que tu écris, il faudrait que ta TextBox retourne un espace... (surprenant, faudrait voir commentsont initialisées les TextBox)

Donc ça donnerait plutot ceci :
If TextBox1 = ' ' Then Exit Sub

@+Thierry
 

PascalXLD

XLDnaute Barbatruc
Modérateur
re

dans ce cas tu definis une valeur du genre '(aucun)' et tes autres valeurs A, b, c par exemple

Lors de l'initialisation tu indiques que le combobox à pour valeur (aucun)

et à la validation tu testes

if combobox.value='(aucun)' then
range(tacellule)=''
else
range(tacellule)=combobox.value
endif

bon courage
 

XC2ONE

XLDnaute Junior
Merci,
je suis un peu largué, à quel niveau je mets ce code en sachant que les combo sont f_ent13 ,14 ,15 et 16 qui nécessite cette fonction :

Private Sub f_b_ok_Click()
If f_ent1 <> '' Then
Sheets('BDD').Select
nb_contact = 0
For i = 8 To 1500
If IsEmpty(Cells(i, 1)) Then
nb_contact = i - 2
Exit For
End If
Next
Sheets('BDD').Cells(nb_contact + 2, 1) = f_ent1
Sheets('BDD').Cells(nb_contact + 2, 2) = f_ent2
Sheets('BDD').Cells(nb_contact + 2, 3) = f_ent3
Sheets('BDD').Cells(nb_contact + 2, 4) = f_ent4
Sheets('BDD').Cells(nb_contact + 2, 5) = f_ent5
Sheets('BDD').Cells(nb_contact + 2, 6) = f_ent6
Sheets('BDD').Cells(nb_contact + 2, 7) = f_ent7
Sheets('BDD').Cells(nb_contact + 2, 8) = f_ent8
Sheets('BDD').Cells(nb_contact + 2, 9) = CDbl(f_ent9.Value)
Sheets('BDD').Cells(nb_contact + 2, 10) = CDbl(f_ent10.Value)
Sheets('BDD').Cells(nb_contact + 2, 11) = f_ent11
Sheets('BDD').Cells(nb_contact + 2, 12) = f_ent12
Sheets('BDD').Cells(nb_contact + 2, 13) = f_ent13
Sheets('BDD').Cells(nb_contact + 2, 14) = f_ent14
Sheets('BDD').Cells(nb_contact + 2, 15) = f_ent15
Sheets('BDD').Cells(nb_contact + 2, 16) = f_ent16
Sheets('BDD').Cells(nb_contact + 2, 18) = f_ent17
Sheets('BDD').Cells(nb_contact + 2, 19) = f_ent18
Sheets('BDD').Cells(nb_contact + 2, 20) = f_ent19
Sheets('BDD').Cells(nb_contact + 2, 21) = f_ent20
Sheets('BDD').Cells(nb_contact + 2, 22) = f_ent21
Sheets('BDD').Cells(nb_contact + 2, 23) = f_ent22
Sheets('BDD').Cells(nb_contact + 2, 24) = f_ent23
Sheets('BDD').Cells(nb_contact + 2, 25) = f_ent24
Sheets('BDD').Cells(nb_contact + 2, 26) = f_ent25
choix_OK = True
f_ent1 = ''
f_ent2 = ''
f_ent3 = ''
f_ent4 = ''
f_ent5 = ''
f_ent6 = ''
f_ent7 = ''
f_ent8 = ''
f_ent9.Value = 0
f_ent10.Value = 0
f_ent11 = ''
f_ent12 = ''
f_ent13 = ''
f_ent14 = ''
f_ent15 = ''
f_ent16 = ''
f_ent17 = ''
f_ent18 = ''
f_ent19 = ''
f_ent20 = ''
f_ent21 = ''
f_ent22 = ''
f_ent23 = ''
f_ent24 = ''
f_ent25 = ''
f_ent1.SetFocus
Else 'Si première zone à blanc
choix_OK = False
Unload f_nouveau
End If

a+
 
N

Nanard

Guest
Bonsoir XC2ONE, le forum,pascal 76, @+ Thierry,

Tu peux entrer cette formule qui comptabilise dans la colonne C de C1 à C14 le nombre de cellules vides que tu retrancheras à ton résultat NBVAL de ta base, ainsi tu élimines la comptabilisation des cellules vides !

=NB.SI(C1:C14;'')

Ce n'est pas du VBA, mais ça doit 'marcher'

@+

Nanard
 

PascalXLD

XLDnaute Barbatruc
Modérateur
DAns ton code

Sheets('BDD').Cells(nb_contact + 2, 12) = f_ent12
if f_ent13.value='(Aucun)' then
Sheets('BDD').Cells(nb_contact + 2, 13) = ''
else
Sheets('BDD').Cells(nb_contact + 2, 13) = f_ent13
end if

et tu continues pareil pourles autres
 

Discussions similaires

  • Question
Microsoft 365 TEXTBOX
Réponses
7
Affichages
410

Membres actuellement en ligne

Aucun membre en ligne actuellement.

Statistiques des forums

Discussions
312 668
Messages
2 090 739
Membres
104 643
dernier inscrit
adriano22