Thank You. Looks like I was doing the good thing. But then, can someone
tell me what's wrong with this:
If DatePart("yyyy", Range("A" & j)) = DatePart("yyyy", DateO) And _
DatePart("mm", Range("A" & j)) = DatePart("mm", DateO) Then
Here is more of the program if you need it to understand:
The point is to have a list of Amount by Month for a product, from a list
where I have amounts per date from a product.
Product is in A, Date in E and Amount in G.
I plan to add a "sort" after this will work.
-------
'Déclaration des variables
Dim i As Integer ' Compteur
Dim j As Integer ' Compteur
Dim DateO As Date ' Année et mois
Dim Montant As Currency ' Montant du recouvrement
--------
Sub LectureCode()
i = 5 'initialisation du compteur
Sheets("Principale").Select
'Lecture du code
Do While Range("A" & i) < Empty
DateO = Range("E" & i)
Montant = Range("G" & i)
'Série de tests
Select Case Range("A" & i)
[Here I chose a sheet with select case, I know it works, I use it in an
other program]
End Select
'Inscription des données
j = 16 ' Première ligne d'écriture des
dates
Do While Range("A" & j) < Empty ' On passe les lignes déjà
écrites
If DatePart("yyyy", Range("A" & j)) = DatePart("yyyy", DateO) And _
DatePart("mm", Range("A" & j)) = DatePart("mm", DateO) Then
' Si la date existe déjà
Calcul = Range("C" & j) + Montant ' On calcul le nouveau montant
Range("C" & j).FormulaR1C1 = Calcul ' On inscrit le nouveau
montant
Exit Do ' On sort de la boucle
Else
j = j + 1
End If
Loop
If Range("A" & j) = Empty Then ' Si la date n'existe pas
Selection.EntireRow.Insert ' Insertion une ligne
Range("A" & j) = Format(DateO, "yy/mm") ' Inscription de la date
Range("C" & j).FormulaR1C1 = Montant ' Inscription du montant
End If
'
Préparation à la prochaine boucle
i = i + 1
Sheets("Principale").Select
Loop
End Sub
----
Thank you.
Marie
De: "SunTzuComm"
Objet: "If"
VB Syntaxe
Date: 4 juin 2004 10:53
Here's an example; you can also use Or instead of And:
If A = B And C = D Then
If E = F And G = H Then
... and so on
End If
End If
Regards,
Wes