SYNTAXE COLLER VALEUR Apres formule

poolito

XLDnaute Nouveau
Bonjour,

je cherche a ameliorer cette syntaxe mais en vain.
je copie ma formule et ensuite la valeur obtenue. mais ca mouline trop a mon gout

Private Sub Worksheet_Change(ByVal Target As Range)
Dim fdesign
fdesign = "=IF(RC[-1]<>"""",VLOOKUP(RC[-1],PRODUIT!R1C[-1]:R65536C[7],2,0),"""")"
If Target.Count > 1 Then Exit Sub
If Target.Column = 1 Then Target.Offset(0, 1) = fdesign
Target.Offset(0, 1) = Target.Offset(0, 1).Value

End Sub

Si quelqu'un a une idée pour inserer le .value directement sur la premiere ligne
 

john

XLDnaute Impliqué
Re : SYNTAXE COLLER VALEUR Apres formule

Bonjour,
Essaie avec ceci :

Dim fdesign
fdesign = "=IF(RC[-1]<>"""",VLOOKUP(RC[-1],PRODUIT!R1C[-1]:R65536C[7],2,0),"""")"
If Target.Count > 1 Then Exit Sub
If Target.Column = 1 Then
Application.EnableEvents = False
Target.Offset(0, 1) = fdesign
Target.Offset(0, 1) = Target.Offset(0, 1).Value
Application.EnableEvents = True
End If

Bonne journée.
John
 

Robert

XLDnaute Barbatruc
Repose en paix
Re : SYNTAXE COLLER VALEUR Apres formule

Bonjour Poolito, John, bonjour le forum,

Une proposition sans passer par une formule (non testé car pas de fichier exemple) :

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim R As Range
If Target.Column <> 1 Then Exit Sub
If Target.Value <> "" Then
    Set R = Sheets("PRODUIT").Columns(1).Find(Target.Value, , xlValues, xlWhole)
    If Not R Is Nothing Then Target.Offset(0, 1).Value = R.Offset(0, 1).Value
End If
End Sub
 

poolito

XLDnaute Nouveau
Re : SYNTAXE COLLER VALEUR Apres formule

Bonjour Robert, et merci de votre proposition.
Je viens d'ajouter d'autres formules comme ci dessous. Mais je ne comprends pas ou justement sont insérer les formules dans la méthode sans formule que vous proposé? je vous joins un fichier exemple.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim fdesign
Dim funit
Dim fpu
Dim fmontant

fdesign = "=IF(RC[-1]<>"""",VLOOKUP(RC[-1],PRODUIT!R1C[-1]:R65536C[7],2,0),"""")"
funit = "=IF(RC[-7]<>"""",VLOOKUP(RC[-7],PRODUIT!C[-7]:C[-5],3,0),"""")"
fpu = "=IFERROR(IF(RC[-9]="""",IF(RC[2]="""","""",RC[2]),IF(RC[2]="""",RC[45],RC[2])),"""")"
fmontant = "=IFERROR(IF(RC[-2]<>"""",IF(RC[2]="""",SUM(RC[-2]*RC[-1]),""""),""""),"""")"

'si ajout reference
If Target.Count > 1 Then Exit Sub
If Target.Column = 1 Then

Application.DisplayAlerts = False
Application.EnableEvents = False

Target.Offset(0, 1) = fdesign
Target.Offset(0, 7) = funit
Target.Offset(0, 9) = fpu
Target.Offset(0, 10) = fmontant

Target.Offset(0, 1) = Target.Offset(0, 1).Value
Target.Offset(0, 7) = Target.Offset(0, 7).Value
Target.Offset(0, 9) = Target.Offset(0, 9).Value
Target.Offset(0, 10) = Target.Offset(0, 10).Value
Application.EnableEvents = True
End If

'si ajout quantité
If Target.Count > 1 Then Exit Sub
If Target.Column = 9 Then
Application.EnableEvents = False
Target.Offset(0, 2) = fmontant
Target.Offset(0, 2) = Target.Offset(0, 2).Value
Application.EnableEvents = True
End If

'si ajout prix unitaire
If Target.Count > 1 Then Exit Sub
If Target.Column = 10 Then
Application.EnableEvents = False
Target.Offset(0, 1) = fmontant
Target.Offset(0, 1) = Target.Offset(0, 1).Value
Application.DisplayAlerts = True
Application.EnableEvents = True
End If



End Sub
 

Pièces jointes

  • Classeur1.xlsm
    77.2 KB · Affichages: 48
  • Classeur1.xlsm
    77.2 KB · Affichages: 47
  • Classeur1.xlsm
    77.2 KB · Affichages: 57

Discussions similaires

Statistiques des forums

Discussions
312 348
Messages
2 087 508
Membres
103 568
dernier inscrit
NoS