Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
"If" VB Syntaxe
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
"If" VB Syntaxe
Marie
I don't think that "mm" is a valid interval for DatePart. Try using just "m". You can also use Format, which is what I prefer If Format(Range("A" & j).Value, "mm-yyyy") = Format(DateO, "mm-yyyy") Then -- Dick Kusleika MVP - Excel Excel Blog - Daily Dose of Excel www.dicks-blog.com "Marie Lavoie" wrote in message ... 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
"If" VB Syntaxe
Thank you, I was trying to put the date as only month and year and compare,
but was not able. I'll try it. Regards, Marie "Dick Kusleika" a écrit dans le message de ... Marie I don't think that "mm" is a valid interval for DatePart. Try using just "m". You can also use Format, which is what I prefer If Format(Range("A" & j).Value, "mm-yyyy") = Format(DateO, "mm-yyyy") Then -- Dick Kusleika MVP - Excel Excel Blog - Daily Dose of Excel www.dicks-blog.com "Marie Lavoie" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell | Excel Discussion (Misc queries) | |||
change "true" and "false" to "availble" and "out of stock" | Excel Worksheet Functions | |||
HELP on "left","right","find","len","substitute" functions | Excel Discussion (Misc queries) | |||
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next | New Users to Excel | |||
"If" VB Syntaxe | Excel Programming |