Comment spliter une date dans différentes cellules excel vb6

kobejul08 Messages postés 113 Date d'inscription vendredi 15 avril 2005 Statut Membre Dernière intervention 3 octobre 2005 - 12 août 2005 à 15:55
jhary69 Messages postés 81 Date d'inscription jeudi 29 juillet 2004 Statut Membre Dernière intervention 22 juillet 2007 - 13 août 2005 à 15:57
Bonjour,

comment le titre l'indique j'ai une date (10/01/2005) comme l'exemple si contre

je voudrais l'écrire dans trois cellule différentes .. comment dois je faire
je vous montre ce que j'ai codé et dites moi ou ça blesse Merci
Dim Jdate As Date

monxl.Cells(i, 2).Value = Day(monxl2.Cells(j, 2))
monxl.Cells(i, 3).Value = Month(monxl2.Cells(j, 3))
monxl.Cells(i, 5).Value = Year(monxl2.Cells(j, 5))

If monxl2.Cells(j, 3).Value = 1 Then
monxl2.Cells(j, 3) = "janvier"
End If
If monxl2.Cells(j, 3).Value = 2 Then
monxl2.Cells(j, 3) = "février"
End If
If monxl2.Cells(j, 3).Value = 3 Then
monxl2.Cells(j, 3) = "mars"
End If
If monxl2.Cells(j, 3).Value = 4 Then
monxl2.Cells(j, 3) = "avril"
End If
If monxl2.Cells(j, 3).Value = 5 Then
monxl2.Cells(j, 3) = "mai"
End If
If monxl2.Cells(j, 3).Value = 6 Then
monxl2.Cells(j, 3) = "juin"
End If
If monxl2.Cells(j, 3).Value = 7 Then
monxl2.Cells(j, 3) = "juillet"
End If
If monxl2.Cells(j, 3).Value = 8 Then
monxl2.Cells(j, 3) = "août"
End If
If monxl2.Cells(j, 3).Value = 9 Then
monxl2.Cells(j, 3) = "septembre"
End If
If monxl2.Cells(j, 3).Value = 10 Then
monxl2.Cells(j, 3) = "octobre"
End If
If monxl2.Cells(j, 3).Value = 11 Then
monxl2.Cells(j, 3) = "novembre"
End If
If monxl2.Cells(j, 3).Value = 12 Then
monxl2.Cells(j, 3) = "décembre"
End If

3 réponses

jhary69 Messages postés 81 Date d'inscription jeudi 29 juillet 2004 Statut Membre Dernière intervention 22 juillet 2007
12 août 2005 à 16:07
salut,

monxl c'est une variable de type Sheet ?? si oui ok coté prog, si non Cells depend d'un objet Sheet ou Worksheet par directement du l'objet Workbook auquel cas

wbMonClasseur.Worksheets("MaFeuille").Cells(......

ta date à l'origine est au format date ??

Si oui :

monxl.Cells(i, 2).Value = format(monxl2.Cells(j, 2),"dd")
monxl.Cells(i, 3).Value = format(monxl2.Cells(j, 3),"mmmm") ' ca te donne directement Janvier, Fevrier, ...
monxl.Cells(i, 5).Value = format(monxl2.Cells(j, 5),"yy") ' si année sur 2 chiffres
ou
monxl.Cells(i, 5).Value = format(monxl2.Cells(j, 5),"yyyy") ' si année sur 4 chiffres

C'est + simple et rapide !

A+

Christophe.
0
kobejul08 Messages postés 113 Date d'inscription vendredi 15 avril 2005 Statut Membre Dernière intervention 3 octobre 2005
12 août 2005 à 16:16
bon en fait je me rend compte que je fais des boulettes dans ce petit programme p-ê pourras tu m'aider

j'ai un fichier excel "EchantillonFichierCommandes.xls" c'est monxl2
et j'aimerais aller écrire dans monxl donc dans ce fichier qui s'appelle"NEW Commandes ericsson-nokia corrigé 09-08.xls"(monxl)

je veux juste recopier dans monxl ce qu'il ya dans monxl2

sauf que dans monxl2 j'ai une date en B2 ainsi 10/10/2005
et j'aimerais que dans monxl en B2 j'ai le jour donc 10
C2 j'ai le mois donc octobre
!!E2 j'ai l'année 2005
peux tu regarder mon prog. mais me dire ce qui ne va pas puisque il me demande meme pas si je veux enregistrer Merci.

monxl2.Workbooks.Open "C:\EchantillonFichierCommandes.xls"
monxl.Workbooks.Open "C:\NEW Commandes ericsson-nokia corrigé 09-08.xls"


For i = 1 To 15000
If monxl.Cells(i, 1).Value = "" Then
Exit For
End If
Next
For j = 2 To 15000
If monxl2.Cells(j, 2).Value = "" Then
Exit For
End If


monxl.Cells(i, 1).Value = monxl2.Cells(j, 1).Value
monxl.Cells(i, 4).Value = monxl2.Cells(j, 4).Value
monxl.Cells(i, 6).Value = monxl2.Cells(j, 6).Value
monxl.Cells(i, 7).Value = monxl2.Cells(j, 7).Value
monxl.Cells(i, 8).Value = monxl2.Cells(j, 8).Value
monxl.Cells(i, 9).Value = monxl2.Cells(j, 9).Value
monxl.Cells(i, 10).Value = monxl2.Cells(j, 10).Value
monxl.Cells(i, 11).Value = monxl2.Cells(j, 11).Value
monxl.Cells(i, 12).Value = monxl2.Cells(j, 12).Value
monxl.Cells(i, 13).Value = monxl2.Cells(j, 13).Value
monxl.Cells(i, 14).Value = monxl2.Cells(j, 14).Value
monxl.Cells(i, 15).Value = monxl2.Cells(j, 15).Value
monxl.Cells(i, 16).Value = monxl2.Cells(j, 16).Value
monxl.Cells(i, 17).Value = monxl2.Cells(j, 17).Value
monxl.Cells(i, 18).Value = monxl2.Cells(j, 18).Value
monxl.Cells(i, 19).Value = monxl2.Cells(j, 19).Value
monxl.Cells(i, 20).Value = monxl2.Cells(j, 20).Value
monxl.Cells(i, 21).Value = monxl2.Cells(j, 21).Value
monxl.Cells(i, 22).Value = monxl2.Cells(j, 22).Value
monxl.Cells(i, 23).Value = monxl2.Cells(j, 23).Value
'monxl.Cells(i, 1).Value = monxl2.Cells(j, 24).Value
'monxl.Cells(i, 1).Value = monxl2.Cells(j, 25).Value
'monxl.Cells(i, 1).Value = monxl2.Cells(j, 1).Value
'monxl.Cells(i, 1).Value = monxl2.Cells(j, 1).Value
'monxl.Cells(i, 1).Value = monxl2.Cells(j, 1).Value
'monxl.Cells(i, 1).Value = monxl2.Cells(j, 1).Value
'monxl.Cells(i, 1).Value = monxl2.Cells(j, 1).Value


Dim Jdate As Date

monxl.Cells(i, 2).Value = Day(monxl2.Cells(j, 2).Value)
monxl.Cells(i, 3).Value = Month(monxl2.Cells(j, 2).Value)
monxl.Cells(i, 5).Value = Year(monxl2.Cells(j, 2).Value)

If monxl2.Cells(j, 3).Value = 1 Then
monxl2.Cells(j, 3) = "janvier"
End If
If monxl2.Cells(j, 3).Value = 2 Then
monxl2.Cells(j, 3) = "février"
End If
If monxl2.Cells(j, 3).Value = 3 Then
monxl2.Cells(j, 3) = "mars"
End If
If monxl2.Cells(j, 3).Value = 4 Then
monxl2.Cells(j, 3) = "avril"
End If
If monxl2.Cells(j, 3).Value = 5 Then
monxl2.Cells(j, 3) = "mai"
End If
If monxl2.Cells(j, 3).Value = 6 Then
monxl2.Cells(j, 3) = "juin"
End If
If monxl2.Cells(j, 3).Value = 7 Then
monxl2.Cells(j, 3) = "juillet"
End If
If monxl2.Cells(j, 3).Value = 8 Then
monxl2.Cells(j, 3) = "août"
End If
If monxl2.Cells(j, 3).Value = 9 Then
monxl2.Cells(j, 3) = "septembre"
End If
If monxl2.Cells(j, 3).Value = 10 Then
monxl2.Cells(j, 3) = "octobre"
End If
If monxl2.Cells(j, 3).Value = 11 Then
monxl2.Cells(j, 3) = "novembre"
End If
If monxl2.Cells(j, 3).Value = 12 Then
monxl2.Cells(j, 3) = "décembre"
End If




i = i + 1
Next


End Sub
0
jhary69 Messages postés 81 Date d'inscription jeudi 29 juillet 2004 Statut Membre Dernière intervention 22 juillet 2007
13 août 2005 à 15:57
re,

monxl2.Workbooks.Open "C:\EchantillonFichierCommandes.xls"
monxl.Workbooks.Open "C:\NEW Commandes ericsson-nokia corrigé 09-08.xls"

a remplacer par

Dim monxl as Excel.Workbook
Dim monxl2 as Excel.Workbook

Set monxl = Workbooks.Open "C:\NEW Commandes ericsson-nokia corrigé 09-08.xls"
Set monxl2 = Workbooks.Open "C:\EchantillonFichierCommandes.xls"


comme ca, ca devrait mieux marcher ...

De plus tu peux modifier la suite :

monxl.Cells(i, 2).Value = Day(monxl2.Cells(j, 2).Value)
monxl.Cells(i, 3).Value = Month(monxl2.Cells(j, 2).Value)
monxl.Cells(i, 5).Value = Year(monxl2.Cells(j, 2).Value)

If monxl2.Cells(j, 3).Value = 1 Then
monxl2.Cells(j, 3) = "janvier"
End If
If monxl2.Cells(j, 3).Value = 2 Then
monxl2.Cells(j, 3) = "février"
End If
If monxl2.Cells(j, 3).Value = 3 Then
monxl2.Cells(j, 3) = "mars"
End If
If monxl2.Cells(j, 3).Value = 4 Then
monxl2.Cells(j, 3) = "avril"
End If
If monxl2.Cells(j, 3).Value = 5 Then
monxl2.Cells(j, 3) = "mai"
End If
If monxl2.Cells(j, 3).Value = 6 Then
monxl2.Cells(j, 3) = "juin"
End If
If monxl2.Cells(j, 3).Value = 7 Then
monxl2.Cells(j, 3) = "juillet"
End If
If monxl2.Cells(j, 3).Value = 8 Then
monxl2.Cells(j, 3) = "août"
End If
If monxl2.Cells(j, 3).Value = 9 Then
monxl2.Cells(j, 3) = "septembre"
End If
If monxl2.Cells(j, 3).Value = 10 Then
monxl2.Cells(j, 3) = "octobre"
End If
If monxl2.Cells(j, 3).Value = 11 Then
monxl2.Cells(j, 3) = "novembre"
End If
If monxl2.Cells(j, 3).Value = 12 Then
monxl2.Cells(j, 3) = "décembre"
End If

a remplacer par

monxl.Cells(i, 2).Value = format(monxl2.Cells(j, 2),"dd")
monxl.Cells(i, 3).Value = format(monxl2.Cells(j, 3),"mmmm") ' ca te donne directement Janvier, Fevrier, ...
monxl.Cells(i, 5).Value = format(monxl2.Cells(j, 5),"yy") ' si année sur 2 chiffres "yy" sinon si sur 4 chiffres "yyyy"


A+

Christophe.
0
Rejoignez-nous