r0man0
Messages postés41Date d'inscriptionvendredi 3 décembre 2010StatutMembreDernière intervention11 février 2014
-
20 mars 2013 à 15:08
Utilisateur anonyme -
14 mai 2013 à 23:22
Bonjour à toutes et à tous,
voilà j'ai ce code sur lequel je travaille depuis qques mois maintenant,
Dim btnChoisi As String
Private Sub BtNG_Click()
btnChoisi = "NG"
End Sub
Private Sub BtNV_Click()
btnChoisi = "NV"
End Sub
Private Sub BtND_Click()
btnChoisi = "ND"
End Sub
Private Sub Label2_Click()
End Sub
Private Sub CommandButton1_Click()
Dim Wss, WsC As Worksheet
Dim TBLF, MaPlage, MPD, Destination As Range
Dim CIBLE As Variant
Dim DerLigS, i As Long
Set Wss = Sheets("BdD")
Set WsC = Sheets("CR_INTER")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
WsC.Activate
WsC.Range("A2:T3").ClearContents
If Me.RNSI.Value = "" Then
Range("V2").FormulaR1C1 = "OPPORTUNITE"
Range("V3").FormulaR1C1 = "OPPORTUNITE"
Me.RNSI.SetFocus
End If
If Me.BtNG.Value + Me.BtNV.Value + Me.BtND.Value = 0 Then
MsgBox "vous devez spécifier la configuration capteur : NG, NV ou ND !"
Exit Sub
End If
If Me.CLICHE.Value = "" Then
MsgBox "Vous devez indiqué le nombre de PDV !"
Me.CLICHE.SetFocus
Exit Sub
End If
Select Case btnChoisi
Case "NG"
If Sheets("CR_INTER").Range("P2").Value = "" Then
Range("P2").FormulaR1C1 = "1"
Range("Q2").FormulaR1C1 = CLICHE.Value
End If
If Sheets("CR_INTER").Range("P2").Value <> "" Then
Range("P2").FormulaR1C1 = Range("Q2").Value + 1
Range("Q2").FormulaR1C1 = Range("Q2").Value + CLICHE.Value
End If
Case "NV"
If Sheets("CR_INTER").Range("P2").Value = "" Then
Range("R2").FormulaR1C1 = "1"
Range("S2").FormulaR1C1 = CLICHE.Value
End If
If Sheets("CR_INTER").Range("P2").Value <> "" Then
Range("R2").FormulaR1C1 = Range("Q2").Value + 1
Range("S2").FormulaR1C1 = Range("Q2").Value + CLICHE.Value
Case "ND"
If Sheets("CR_INTER").Range("P2").Value = "" Then
Range("T2").FormulaR1C1 = "1"
Range("U2").FormulaR1C1 = CLICHE.Value
End If
If Sheets("CR_INTER").Range("P2").Value <> "" Then
Range("T2").FormulaR1C1 = Range("Q2").Value + 1
Range("U2").FormulaR1C1 = Range("Q2").Value + CLICHE.Value
End Select
WsC.Activate
Cells(2, 1).Value = Date
Cells(2, 2).Value = Time
With Workbooks("GPS.xls").Sheets("Feuil1")
Cells(3, 1).Value = .Cells(2, 1)
Cells(3, 2).Value = .Cells(2, 2)
Cells(2, 4).Value = .Cells(2, 10)
Cells(2, 5).Value = .Cells(2, 11)
Cells(2, 8).Value = .Cells(2, 5)
Cells(2, 9).Value = .Cells(2, 3)
Cells(2, 10).Value = .Cells(2, 4)
Cells(3, 8).Value = .Cells(2, 8)
Cells(3, 9).Value = .Cells(2, 6)
Cells(3, 10).Value = .Cells(2, 7)
End With
DerLigS = Wss.Cells(Wss.Columns(1).Cells.Count, 1).End(xlUp).Row
Set MaPlage = Wss.Range(Wss.Cells(1, 1), Wss.Cells(DerLigS, 1))
Set TBLF = MaPlage.Find(Me.RNSI.Value, LookIn:=xlValues)
If Not TBLF Is Nothing Then
WsC.Cells(2, 3) = Wss.Cells(TBLF.Row, 7)
WsC.Cells(2, 6) = Wss.Cells(TBLF.Row, 2)
WsC.Cells(2, 7) = Wss.Cells(TBLF.Row, 6)
WsC.Cells(2, 12) = Wss.Cells(TBLF.Row, 4)
WsC.Cells(3, 12) = Wss.Cells(TBLF.Row, 5)
WsC.Cells(3, 4) = Wss.Cells(TBLF.Row, 3)
End If
Range("L2").TextToColumns Destination:=Range("L2"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(1, 1), Array(3, 1), Array(5, 1)), _
TrailingMinusNumbers:=True
Range("L3").TextToColumns Destination:=Range("L3"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(1, 1), Array(4, 1), Array(6, 1)), _
TrailingMinusNumbers:=True
Range("J2:J3").TextToColumns Destination:=Range("J2"), DataType:=xlDelimited, _
TextQualifier:=xlNone, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:=".", FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
Range("W2").FormulaR1C1 = "=(R[0]C[-12]*60)/10000"
Range("W3").FormulaR1C1 = "=(R[0]C[-12]*60)/10000"
Range("W2:W3").Copy
Range("K2:K3").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Set Destination = Sheets("Feuil2").Range("A65535").End(xlUp).Offset(1, 0)
Set MPD = WsC.Range("A2:S3")
MPD.Copy Destination
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub CommandButton3_Click()
Sheets("Feuil2").Activate
End Sub
Private Sub CommandButton4_Click()
Sheets("Feuil2").Cells.ClearContents
End Sub
J'utilise un userform avec 3 optionbutton, pour chaque optionbutton une règle d'incrémentation,
quand je test mon code, il me dit erreur compilation : case sans select case, j'ai essayé différente manip mais sans succès. Pourriez-vous me dire ce qu'il ne va pas.
Merci.
ucfoutu
Messages postés18038Date d'inscriptionlundi 7 décembre 2009StatutModérateurDernière intervention11 avril 2018219 21 mars 2013 à 10:54
Un code bien indenté est indenté de telle manière que chaque début de bloc et sa fin de bloc se retrouvent au même niveau d'indentation.
Sous cette forme (exemple) , donc :
Private sub .....
with ....
.....
If ..... Then ....
.....
end if
....
end with
end sub
________________________
Réponse exacte ? => "REPONSE ACCEPTEE" facilitera les recherches.
Pas d'aide en ligne installée ? => ne comptez pas sur moi pour simplement répéter son contenu. Je n'interviendrai que si nécessité de la compléter.
ucfoutu
Messages postés18038Date d'inscriptionlundi 7 décembre 2009StatutModérateurDernière intervention11 avril 2018219 20 mars 2013 à 15:48
Bonjour (et un salut à JMO)
Ce dont il se serait immédiatement rendu compte en indentant proprement son code.
________________________
Réponse exacte ? => "REPONSE ACCEPTEE" facilitera les recherches.
Pas d'aide en ligne installée ? => ne comptez pas sur moi pour simplement répéter son contenu. Je n'interviendrai que si nécessité de la compléter.
bonjour à tous
pourquoi ne pas utiliser le IF THEN ELSE ?
If Sheets("CR_INTER").Range("P2").Value = "" Then
Range("P2").FormulaR1C1 = "1"
Range("Q2").FormulaR1C1 = CLICHE.Value
End If
If Sheets("CR_INTER").Range("P2").Value <> "" Then
Range("P2").FormulaR1C1 = Range("Q2").Value + 1
Range("Q2").FormulaR1C1 = Range("Q2").Value + CLICHE.Value
End If
à remplacer par
If Sheets("CR_INTER").Range("P2").Value = "" Then
Range("P2").FormulaR1C1 = "1"
Range("Q2").FormulaR1C1 = CLICHE.Value
Else
Range("P2").FormulaR1C1 = Range("Q2").Value + 1
Range("Q2").FormulaR1C1 = Range("Q2").Value + CLICHE.Value
End If
La théorie, c'est quand on sait tout et que rien ne fonctionne. La pratique, c'est quand tout fonctionne et que personne ne sait pourquoi.
GRENIER Alain
Vous n’avez pas trouvé la réponse que vous recherchez ?