Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

format de date dans un listbox

3 réponses
Avatar
nicolas S
Bonjour,

J'ai un problème de date avant le 12 du mois, le 10/02/06 devient le
02/10/06 quand j'imprime un listbox par le code suivant



Private Sub impCB_Click()

Dim n%, m%

'Application.ScreenUpdating = False

'With Workbooks.Add

'With .Sheets(2)

With ActiveWorkbook.Worksheets("feuil2").Activate

Range(Cells(2, 2), Cells(ListBox2.ListCount + 1,
ListBox2.ColumnCount + 1)).Value = ListBox2.List

Me.Hide

Columns.AutoFit

With Sheets(1).PageSetup

.FitToPagesWide = 1

.Zoom = False

End With

ActiveSheet.UsedRange.PrintPreview

End With

'.Close False

'End With

'Application.ScreenUpdating = True

Range(Cells(2, 2), Cells(ListBox2.ListCount + 1,
ListBox2.ColumnCount + 1)).Value = ""

Me.Show

End Sub



Listbox2 est rempli comme suit:



Private Sub recheCB_Click()

Dim aa, bb

On Error GoTo fiin

ii = -1

AP = CDate(apTB) * 1

AV = CDate(avTB) * 1

lc1 = ListBox1.ListCount

lc2 = ListBox2.ListCount

ListBox2.Clear

For ii = 1 To lc1



If AV > ListBox1.List(ii, 0) And AP < ListBox1.List(ii, 0) Then

If Not ComboBox1 = "" Then



If Not ComboBox1 = ListBox1.List(ii, 1) Then GoTo ret

ListBox2.AddItem CDate(ListBox1.List(ii, 0))

ListBox2.List(ListBox2.ListCount - 1, 1) =
ListBox1.List(ii, 1)

ListBox2.List(ListBox2.ListCount - 1, 2) =
ListBox1.List(ii, 2)



aa = aa + 1

bb = bb + ListBox1.List(ii, 2)

GoTo ret



End If

ListBox2.AddItem CDate(ListBox1.List(ii, 0))

ListBox2.List(ListBox2.ListCount - 1, 1) = ListBox1.List(ii,
1)

ListBox2.List(ListBox2.ListCount - 1, 2) = ListBox1.List(ii,
2)



aa = aa + 1

bb = bb + ListBox1.List(ii, 2)



End If

If ListBox1.List(ii, 0) = "" Then GoTo fin

ret:

Next

fin:

ListBox2.AddItem ""

ListBox2.List(ListBox2.ListCount - 1, 1) = ""

ListBox2.List(ListBox2.ListCount - 1, 2) = ""



ListBox2.AddItem "Nb de traite"

ListBox2.List(ListBox2.ListCount - 1, 1) = "euro par jours"

ListBox2.List(ListBox2.ListCount - 1, 2) = "total"



ListBox2.AddItem aa

ListBox2.List(ListBox2.ListCount - 1, 1) = CLng(bb / (AV -
AP))

ListBox2.List(ListBox2.ListCount - 1, 2) = bb

fiin:

End Sub



Listbox1 est rempli comme suit:



ListBox1.RowSource = "b3:d4000" dans Private Sub UserForm_activate()



La colonne b de la feuille 1 est remplie comme suit



Private Sub enrCB_Click()

Range("b1").Select



'ActiveCell.Offset(-1, 2).Select

Selection.End(xlDown).Select

ActiveCell.Offset(1, 0).Select

ActiveCell.Value = Format(CDate(echeTB), "dd/mmm/yyyy")

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = nomlaboTB.Value

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = MtsTB.Value

echeTB.SetFocus

End Sub



Je ne sais pas comment remédier à ce problème, pouvez vous m'aider si j'ai
été clair

3 réponses

Avatar
lSteph
Bonjour,

En totale abstraction du reste du code:

As-tu essayé avec datevalue?

lSteph

"nicolas S" surf.fr> a écrit dans le message de
news: dt70l6$aeg$
Bonjour,

J'ai un problème de date avant le 12 du mois, le 10/02/06 devient le
02/10/06 quand j'imprime un listbox par le code suivant



Private Sub impCB_Click()

Dim n%, m%

'Application.ScreenUpdating = False

'With Workbooks.Add

'With .Sheets(2)

With ActiveWorkbook.Worksheets("feuil2").Activate

Range(Cells(2, 2), Cells(ListBox2.ListCount + 1,
ListBox2.ColumnCount + 1)).Value = ListBox2.List

Me.Hide

Columns.AutoFit

With Sheets(1).PageSetup

.FitToPagesWide = 1

.Zoom = False

End With

ActiveSheet.UsedRange.PrintPreview

End With

'.Close False

'End With

'Application.ScreenUpdating = True

Range(Cells(2, 2), Cells(ListBox2.ListCount + 1,
ListBox2.ColumnCount + 1)).Value = ""

Me.Show

End Sub



Listbox2 est rempli comme suit:



Private Sub recheCB_Click()

Dim aa, bb

On Error GoTo fiin

ii = -1

AP = CDate(apTB) * 1

AV = CDate(avTB) * 1

lc1 = ListBox1.ListCount

lc2 = ListBox2.ListCount

ListBox2.Clear

For ii = 1 To lc1



If AV > ListBox1.List(ii, 0) And AP < ListBox1.List(ii, 0) Then

If Not ComboBox1 = "" Then



If Not ComboBox1 = ListBox1.List(ii, 1) Then GoTo ret

ListBox2.AddItem CDate(ListBox1.List(ii, 0))

ListBox2.List(ListBox2.ListCount - 1, 1) =
ListBox1.List(ii, 1)

ListBox2.List(ListBox2.ListCount - 1, 2) =
ListBox1.List(ii, 2)



aa = aa + 1

bb = bb + ListBox1.List(ii, 2)

GoTo ret



End If

ListBox2.AddItem CDate(ListBox1.List(ii, 0))

ListBox2.List(ListBox2.ListCount - 1, 1) = ListBox1.List(ii,
1)

ListBox2.List(ListBox2.ListCount - 1, 2) = ListBox1.List(ii,
2)



aa = aa + 1

bb = bb + ListBox1.List(ii, 2)



End If

If ListBox1.List(ii, 0) = "" Then GoTo fin

ret:

Next

fin:

ListBox2.AddItem ""

ListBox2.List(ListBox2.ListCount - 1, 1) = ""

ListBox2.List(ListBox2.ListCount - 1, 2) = ""



ListBox2.AddItem "Nb de traite"

ListBox2.List(ListBox2.ListCount - 1, 1) = "euro par jours"

ListBox2.List(ListBox2.ListCount - 1, 2) = "total"



ListBox2.AddItem aa

ListBox2.List(ListBox2.ListCount - 1, 1) = CLng(bb / (AV -
AP))

ListBox2.List(ListBox2.ListCount - 1, 2) = bb

fiin:

End Sub



Listbox1 est rempli comme suit:



ListBox1.RowSource = "b3:d4000" dans Private Sub UserForm_activate()



La colonne b de la feuille 1 est remplie comme suit



Private Sub enrCB_Click()

Range("b1").Select



'ActiveCell.Offset(-1, 2).Select

Selection.End(xlDown).Select

ActiveCell.Offset(1, 0).Select

ActiveCell.Value = Format(CDate(echeTB), "dd/mmm/yyyy")

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = nomlaboTB.Value

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = MtsTB.Value

echeTB.SetFocus

End Sub



Je ne sais pas comment remédier à ce problème, pouvez vous m'aider si j'ai
été clair




Avatar
nicolas S
je vien d'essayer, sans résultats.
la solution que j'ai trouvé c'est de "transformer" 10/02/06 par exemple en
texte avec ceci
TextBox1 = CDate(ListBox1.List(ii, 0))
cc = TextBox1 & "_"
ListBox2.AddItem cc
Ce n'est pas génial, mais cela marche.
merci de ton aide
"lSteph" a écrit dans le message de news:

Bonjour,

En totale abstraction du reste du code:

As-tu essayé avec datevalue?

lSteph

"nicolas S" surf.fr> a écrit dans le message de
news: dt70l6$aeg$
Bonjour,

J'ai un problème de date avant le 12 du mois, le 10/02/06 devient le
02/10/06 quand j'imprime un listbox par le code suivant



Private Sub impCB_Click()

Dim n%, m%

'Application.ScreenUpdating = False

'With Workbooks.Add

'With .Sheets(2)

With ActiveWorkbook.Worksheets("feuil2").Activate

Range(Cells(2, 2), Cells(ListBox2.ListCount + 1,
ListBox2.ColumnCount + 1)).Value = ListBox2.List

Me.Hide

Columns.AutoFit

With Sheets(1).PageSetup

.FitToPagesWide = 1

.Zoom = False

End With

ActiveSheet.UsedRange.PrintPreview

End With

'.Close False

'End With

'Application.ScreenUpdating = True

Range(Cells(2, 2), Cells(ListBox2.ListCount + 1,
ListBox2.ColumnCount + 1)).Value = ""

Me.Show

End Sub



Listbox2 est rempli comme suit:



Private Sub recheCB_Click()

Dim aa, bb

On Error GoTo fiin

ii = -1

AP = CDate(apTB) * 1

AV = CDate(avTB) * 1

lc1 = ListBox1.ListCount

lc2 = ListBox2.ListCount

ListBox2.Clear

For ii = 1 To lc1



If AV > ListBox1.List(ii, 0) And AP < ListBox1.List(ii, 0) Then

If Not ComboBox1 = "" Then



If Not ComboBox1 = ListBox1.List(ii, 1) Then GoTo ret

ListBox2.AddItem CDate(ListBox1.List(ii, 0))

ListBox2.List(ListBox2.ListCount - 1, 1) =
ListBox1.List(ii, 1)

ListBox2.List(ListBox2.ListCount - 1, 2) =
ListBox1.List(ii, 2)



aa = aa + 1

bb = bb + ListBox1.List(ii, 2)

GoTo ret



End If

ListBox2.AddItem CDate(ListBox1.List(ii, 0))

ListBox2.List(ListBox2.ListCount - 1, 1) = ListBox1.List(ii,
1)

ListBox2.List(ListBox2.ListCount - 1, 2) = ListBox1.List(ii,
2)



aa = aa + 1

bb = bb + ListBox1.List(ii, 2)



End If

If ListBox1.List(ii, 0) = "" Then GoTo fin

ret:

Next

fin:

ListBox2.AddItem ""

ListBox2.List(ListBox2.ListCount - 1, 1) = ""

ListBox2.List(ListBox2.ListCount - 1, 2) = ""



ListBox2.AddItem "Nb de traite"

ListBox2.List(ListBox2.ListCount - 1, 1) = "euro par jours"

ListBox2.List(ListBox2.ListCount - 1, 2) = "total"



ListBox2.AddItem aa

ListBox2.List(ListBox2.ListCount - 1, 1) = CLng(bb / (AV -
AP))

ListBox2.List(ListBox2.ListCount - 1, 2) = bb

fiin:

End Sub



Listbox1 est rempli comme suit:



ListBox1.RowSource = "b3:d4000" dans Private Sub UserForm_activate()



La colonne b de la feuille 1 est remplie comme suit



Private Sub enrCB_Click()

Range("b1").Select



'ActiveCell.Offset(-1, 2).Select

Selection.End(xlDown).Select

ActiveCell.Offset(1, 0).Select

ActiveCell.Value = Format(CDate(echeTB), "dd/mmm/yyyy")

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = nomlaboTB.Value

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = MtsTB.Value

echeTB.SetFocus

End Sub



Je ne sais pas comment remédier à ce problème, pouvez vous m'aider si
j'ai été clair








Avatar
michdenis
Bonjour Nicolas,

| J'ai un problème de date avant le 12 du mois, le 10/02/06 devient le
| 02/10/06 quand j'imprime un listbox par le code suivant

En VBA, lorsque tu as une ligne de code qui utilise cette chaîne : 10/02/06

Excel sait que cela représente une date... mais comme tu ne lui as
pas dit expressément la manière d'interpréter cette chaîne de caractère,
VBA utilise le format américain par défaut qui Mois / jour / année

Afin d'éviter cela, tu peux utiliser une des nombres fonctions date comme :
datevalue() Date() .... à ce moment là, il utilisera le format que tu as défini
dans le panneau de configuration de Windows. Le danger avec cette méthode,
est si ton programme roule sous d'autres configurations de Windows, l'interprétation
de la date risque d'être faussé...!!!

Solution sûre : l'utilisation de la fonction DateSerial(Année,Mois,Jour)


Salutations!




"nicolas S" a écrit dans le message de news: dt70l6$aeg$
Bonjour,

J'ai un problème de date avant le 12 du mois, le 10/02/06 devient le
02/10/06 quand j'imprime un listbox par le code suivant



Private Sub impCB_Click()

Dim n%, m%

'Application.ScreenUpdating = False

'With Workbooks.Add

'With .Sheets(2)

With ActiveWorkbook.Worksheets("feuil2").Activate

Range(Cells(2, 2), Cells(ListBox2.ListCount + 1,
ListBox2.ColumnCount + 1)).Value = ListBox2.List

Me.Hide

Columns.AutoFit

With Sheets(1).PageSetup

.FitToPagesWide = 1

.Zoom = False

End With

ActiveSheet.UsedRange.PrintPreview

End With

'.Close False

'End With

'Application.ScreenUpdating = True

Range(Cells(2, 2), Cells(ListBox2.ListCount + 1,
ListBox2.ColumnCount + 1)).Value = ""

Me.Show

End Sub



Listbox2 est rempli comme suit:



Private Sub recheCB_Click()

Dim aa, bb

On Error GoTo fiin

ii = -1

AP = CDate(apTB) * 1

AV = CDate(avTB) * 1

lc1 = ListBox1.ListCount

lc2 = ListBox2.ListCount

ListBox2.Clear

For ii = 1 To lc1



If AV > ListBox1.List(ii, 0) And AP < ListBox1.List(ii, 0) Then

If Not ComboBox1 = "" Then



If Not ComboBox1 = ListBox1.List(ii, 1) Then GoTo ret

ListBox2.AddItem CDate(ListBox1.List(ii, 0))

ListBox2.List(ListBox2.ListCount - 1, 1) ListBox1.List(ii, 1)

ListBox2.List(ListBox2.ListCount - 1, 2) ListBox1.List(ii, 2)



aa = aa + 1

bb = bb + ListBox1.List(ii, 2)

GoTo ret



End If

ListBox2.AddItem CDate(ListBox1.List(ii, 0))

ListBox2.List(ListBox2.ListCount - 1, 1) = ListBox1.List(ii,
1)

ListBox2.List(ListBox2.ListCount - 1, 2) = ListBox1.List(ii,
2)



aa = aa + 1

bb = bb + ListBox1.List(ii, 2)



End If

If ListBox1.List(ii, 0) = "" Then GoTo fin

ret:

Next

fin:

ListBox2.AddItem ""

ListBox2.List(ListBox2.ListCount - 1, 1) = ""

ListBox2.List(ListBox2.ListCount - 1, 2) = ""



ListBox2.AddItem "Nb de traite"

ListBox2.List(ListBox2.ListCount - 1, 1) = "euro par jours"

ListBox2.List(ListBox2.ListCount - 1, 2) = "total"



ListBox2.AddItem aa

ListBox2.List(ListBox2.ListCount - 1, 1) = CLng(bb / (AV -
AP))

ListBox2.List(ListBox2.ListCount - 1, 2) = bb

fiin:

End Sub



Listbox1 est rempli comme suit:



ListBox1.RowSource = "b3:d4000" dans Private Sub UserForm_activate()



La colonne b de la feuille 1 est remplie comme suit



Private Sub enrCB_Click()

Range("b1").Select



'ActiveCell.Offset(-1, 2).Select

Selection.End(xlDown).Select

ActiveCell.Offset(1, 0).Select

ActiveCell.Value = Format(CDate(echeTB), "dd/mmm/yyyy")

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = nomlaboTB.Value

ActiveCell.Offset(0, 1).Select

ActiveCell.Value = MtsTB.Value

echeTB.SetFocus

End Sub



Je ne sais pas comment remédier à ce problème, pouvez vous m'aider si j'ai
été clair