Probleme de syntaxe

Bonjour à tous,

J'utilise un USERFORM pour alimenter une base de donnée :

J'ai un bouton "VALIDER" avec un code de ce type :

ActiveCell.Offset(0, 22).Value = IIf(IsDate(txtenfant1), txtenfant1, "")

Et j'ai un bouton "MODIFIER" avec le code suivant :

Cells(no_ligne, 24) = txtenfant1

Or cette syntaxe me pose des problème pour des raisons de calculs.

En fait j'aurais aimé trouver une syntaxe qui me permette de dire : si txtenfant1 est une date, la date va alimenter la base, en revanche si txtenfant1 est vide alors faire un clearcontent de la cellule.

Merci d'avance

Bonjour,

pour éviter les problèmes tu devrais préciser la feuille sur laquelle tu agit ..

Dim c as range 'la cellule à tester 
set c = ThisWorkBooks.sheets(1).Cells(no_ligne, 24) 

'Ensuit on utilise la variable c pour agir sur la cellule
if isDate( txtenfant1) then
  c = txtenfant1
else
 c.ClearContents 
endif

Merci pour ta réponse ! mais je n'arrive pas faire fonctionner ce code , quelque chose m’échappe

Voici le code en entier :

Dim no_linge As Integer

Sheets("SOURCES").Select

no_ligne = cbxrecherchenom.ListIndex + 2

If cbxrecherchenom.Value = "" Then

MsgBox ("Veuilllez remplir le champ de la recherche ! ")

Else

Cells(no_ligne, 1) = txtmatricule

Cells(no_ligne, 2) = txtN°Unique

Cells(no_ligne, 3) = txtDate1èredemande

Cells(no_ligne, 4) = txtDaterenouvellement

Cells(no_ligne, 5) = txtNOM

Cells(no_ligne, 6) = txtNOMdeJEUNEFILLE

Cells(no_ligne, 7) = txtprénom

Cells(no_ligne, 8) = txtDatedenaissance

Cells(no_ligne, 9) = cbxNationalité

Cells(no_ligne, 10) = cbxSituationfamille

Cells(no_ligne, 11) = txttelephone

Cells(no_ligne, 12) = txtemail

Cells(no_ligne, 13) = txtadresse1

Cells(no_ligne, 14) = txtadresse2

Cells(no_ligne, 15) = txtcp

Cells(no_ligne, 16) = txtville

Cells(no_ligne, 17) = txtNOMconjointoucoloc

Cells(no_ligne, 18) = txtNOMdeJEUNEFILLEConjoint

Cells(no_ligne, 19) = txtprenomconjoint

Cells(no_ligne, 20) = txtDatedeNaissanceconjoint

Cells(no_ligne, 21) = cbxnationalitéconjoint

Cells(no_ligne, 22) = cbxlienavecdemandeurconjoint

Cells(no_ligne, 23) = txttelephoneconjoint

Cells(no_ligne, 24) = txtenfant1

Cells(no_ligne, 25) = txtenfant2

Cells(no_ligne, 26) = txtenfant3

Cells(no_ligne, 27) = txtenfant4

Cells(no_ligne, 28) = txtenfant5

Cells(no_ligne, 29) = txtenfant6

Cells(no_ligne, 30) = txtenfant7

Cells(no_ligne, 31) = txtenfant8

Cells(no_ligne, 33) = txtHandicapéàcharge

Cells(no_ligne, 34) = txtAutrespersonnesàcharge

Cells(no_ligne, 36) = txtnbredeparts

Cells(no_ligne, 37) = txtcategorielogement

Cells(no_ligne, 38) = txtRevenusannueldemandeur

Cells(no_ligne, 39) = txtRevenusannuelconjoint

Cells(no_ligne, 42) = txtrevenusdemandeurmoins2

Cells(no_ligne, 43) = txtrevenusannuelconjointmoins2

Cells(no_ligne, 46) = txtsalairemensueldemandeur

Cells(no_ligne, 47) = txtsalairemensuelconjoint

Cells(no_ligne, 48) = txtAllocationsmensuellesdemandeur

Cells(no_ligne, 49) = txtAllocationsmensuellesconjoint

Cells(no_ligne, 52) = cbxLogementactuel

Cells(no_ligne, 53) = txtBailleursiHLM

Cells(no_ligne, 54) = txtMontantactuelduloyer

Cells(no_ligne, 55) = txtMontantactueldesAPLouAL

Cells(no_ligne, 58) = cbxGenredelogementactuel

Cells(no_ligne, 59) = cbxTypedelogementactuel

Cells(no_ligne, 60) = cbxMotifdelademandedelogement1

Cells(no_ligne, 61) = cbxMotifdelademandedelogement2

Cells(no_ligne, 62) = cbxMotifdelademandedelogement3

Cells(no_ligne, 63) = cbxGenredelogementrecherché

Cells(no_ligne, 64) = cbxTypedelogementrecherché

Cells(no_ligne, 65) = cbxLogementenRDC

Cells(no_ligne, 66) = cbxLogementsansascenceur

Cells(no_ligne, 67) = txtmontantmaxloyeraveccharges

Cells(no_ligne, 68) = txtmontantprevialouapl

Cells(no_ligne, 70) = txtlocalisationsouhaite1

Cells(no_ligne, 71) = txtlocalisationsouhaite2

Cells(no_ligne, 72) = txtlocalisationsouhaite3

Cells(no_ligne, 73) = cbxextensionscommunes

Cells(no_ligne, 74) = txtspecificiteshandicap

Cells(no_ligne, 75) = txtcommentaire

Cells(no_ligne, 76) = cbxdossiercloture

Cells(no_ligne, 77) = txtdatedecloture

End If

End Sub

J'ai joint mon fichier, Help

Ben , dans ton code en entier je ne vois rien qui ressemble au mien ...

oups oui dsl voici ce que j'ai fait :

Dim no_linge As Integer

Sheets("SOURCES").Select

no_ligne = cbxrecherchenom.ListIndex + 2

If cbxrecherchenom.Value = "" Then

MsgBox ("Veuilllez remplir le champ de la recherche ! ")

Else

Cells(no_ligne, 1) = txtmatricule

Cells(no_ligne, 2) = txtN°Unique

Cells(no_ligne, 3) = txtDate1èredemande

Cells(no_ligne, 4) = txtDaterenouvellement

Cells(no_ligne, 5) = txtNOM

Cells(no_ligne, 6) = txtNOMdeJEUNEFILLE

Cells(no_ligne, 7) = txtprénom

Cells(no_ligne, 8) = txtDatedenaissance

Cells(no_ligne, 9) = cbxNationalité

Cells(no_ligne, 10) = cbxSituationfamille

Cells(no_ligne, 11) = txttelephone

Cells(no_ligne, 12) = txtemail

Cells(no_ligne, 13) = txtadresse1

Cells(no_ligne, 14) = txtadresse2

Cells(no_ligne, 15) = txtcp

Cells(no_ligne, 16) = txtville

Cells(no_ligne, 17) = txtNOMconjointoucoloc

Cells(no_ligne, 18) = txtNOMdeJEUNEFILLEConjoint

Cells(no_ligne, 19) = txtprenomconjoint

Cells(no_ligne, 20) = txtDatedeNaissanceconjoint

Cells(no_ligne, 21) = cbxnationalitéconjoint

Cells(no_ligne, 22) = cbxlienavecdemandeurconjoint

Cells(no_ligne, 23) = txttelephoneconjoint

Dim c As Range 'la cellule à tester

Set c = ThisWorkBooks.Sheets(SOURCES).Cells(no_ligne, 24)

'Ensuit on utilise la variable c pour agir sur la cellule

If IsDate(txtenfant1) Then

c = txtenfant1

Else

c.ClearContents

End If

Cells(no_ligne, 25) = txtenfant2

Cells(no_ligne, 26) = txtenfant3

Cells(no_ligne, 27) = txtenfant4

Cells(no_ligne, 28) = txtenfant5

Cells(no_ligne, 29) = txtenfant6

Cells(no_ligne, 30) = txtenfant7

Cells(no_ligne, 31) = txtenfant8

Cells(no_ligne, 33) = txtHandicapéàcharge

Cells(no_ligne, 34) = txtAutrespersonnesàcharge

Cells(no_ligne, 36) = txtnbredeparts

Cells(no_ligne, 37) = txtcategorielogement

Cells(no_ligne, 38) = txtRevenusannueldemandeur

Cells(no_ligne, 39) = txtRevenusannuelconjoint

Cells(no_ligne, 42) = txtrevenusdemandeurmoins2

Cells(no_ligne, 43) = txtrevenusannuelconjointmoins2

Cells(no_ligne, 46) = txtsalairemensueldemandeur

Cells(no_ligne, 47) = txtsalairemensuelconjoint

Cells(no_ligne, 48) = txtAllocationsmensuellesdemandeur

Cells(no_ligne, 49) = txtAllocationsmensuellesconjoint

Cells(no_ligne, 52) = cbxLogementactuel

Cells(no_ligne, 53) = txtBailleursiHLM

Cells(no_ligne, 54) = txtMontantactuelduloyer

Cells(no_ligne, 55) = txtMontantactueldesAPLouAL

Cells(no_ligne, 58) = cbxGenredelogementactuel

Cells(no_ligne, 59) = cbxTypedelogementactuel

Cells(no_ligne, 60) = cbxMotifdelademandedelogement1

Cells(no_ligne, 61) = cbxMotifdelademandedelogement2

Cells(no_ligne, 62) = cbxMotifdelademandedelogement3

Cells(no_ligne, 63) = cbxGenredelogementrecherché

Cells(no_ligne, 64) = cbxTypedelogementrecherché

Cells(no_ligne, 65) = cbxLogementenRDC

Cells(no_ligne, 66) = cbxLogementsansascenceur

Cells(no_ligne, 67) = txtmontantmaxloyeraveccharges

Cells(no_ligne, 68) = txtmontantprevialouapl

Cells(no_ligne, 70) = txtlocalisationsouhaite1

Cells(no_ligne, 71) = txtlocalisationsouhaite2

Cells(no_ligne, 72) = txtlocalisationsouhaite3

Cells(no_ligne, 73) = cbxextensionscommunes

Cells(no_ligne, 74) = txtspecificiteshandicap

Cells(no_ligne, 75) = txtcommentaire

Cells(no_ligne, 76) = cbxdossiercloture

Cells(no_ligne, 77) = txtdatedecloture

End If

End Sub

Rechercher des sujets similaires à "probleme syntaxe"