PDA

View Full Version : Programme in VBA, help



chuyensinh
03-25-2012, 11:17 AM
Hello,
Someone could help me make the following program, please:

Create a macro with one or more loops of type "DO WHILE" which ask user to enter two values​​: the first value between 1 and 4, the 2nd value between 1 and 3
If for each value, the value entered does not meet the criterion, the program will display the message: "the value entered is not correct" and ask again that value until compliance constraints.

This macro will enter the numbers from 1 to 100 starting from the cell "A1" of sheet 1 by shifting each value of the number of lines corresponding to the first required value and the number of columns corresponding to the requested value 2nd.

mikerickson
03-25-2012, 12:06 PM
This sounds like a homework problem.
If so, the policy of this board (and most others) is that we would be glad to help, but aren't going to do the work for you.

What code do you have so far?

chuyensinh
03-25-2012, 12:11 PM
that what i 've done: Sub Macro3()
'creer un macro avec une ou plusieurs boucles de type DO WHILE qui demander 2 valeurs
'1er valeur comprise entre 1 et 4, 2eme valeur comprise entre 1 et 3
'Si pour chacune des valeurs, la valeur saisie ne repond pas au critere, le programme devra afficher le message: "la valeur saisie n'est pas correcte"
'et demander a nouveau cette valeur jusqu'au respect des contraintes
'Cette macro va inscrire les chiffres entre 1 a 100 en partant de la cellule "A1" de la feuille 1 en se decalant pour chaque valeur
'du nombre de la lignes correspondant a la premiere valeur demandee et du nombre de colonnes correspondant a la 2ieme valeur
'
'
Sheets("Feuil1").Select

Dim valeur1 As Long
Dim valeur2 As Long
Dim compteur As Long
Dim i As Integer
Dim j As Integer
valeur1 = InputBox("Entrez un chiffre entre 1 et 4: ")
compteur = 1
Do While valeur1 <> "1" And valeur1 <> "2" And valeur1 <> "3" And valeur1 <> "4"

MsgBox ("la valeur saisie n'est pas correcte")
valeur1 = InputBox("Re-entrez un chiffre entre 1 et 4: ")
compteur = compteur + 1
Loop
MsgBox valeur1

valeur2 = InputBox("Entrez un chiffre entre 1 et 3: ")
compteur = 1
Do While valeur2 <> "1" And valeur2 <> "2" And valeur2 <> "3"

MsgBox ("la valeur saisie n'est pas correcte")
valeur2 = InputBox("Re-entrez un chiffre entre 1 et 3: ")
compteur = compteur + 1
Loop
MsgBox valeur2
compteur = 1
Do

For i = 0 To valeur1
For j = 0 To valeur2
Range("A1").Offset(i, j) = compteur
compteur = compteur + 1
Next j
Next i
Loop While compteur > 100
End Sub

Bob Phillips
03-25-2012, 12:34 PM
And what is right, what is wrong, in that code?