Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default "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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default "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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default "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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
"If" VB Syntaxe Marie Lavoie Excel Programming 2 June 4th 04 03:53 PM


All times are GMT +1. The time now is 03:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"