Programation formule en VBA
Résolu
Akka_31
-
Akka_31 -
Akka_31 -
Bonjour,
Ca fait plusieurs jour que je cherche à encoder une formule IF sous VBA, pour un classeur Excel.
Je n'arrive pâs à encoder un if avec un autre if dans la formule suivante :
ActiveCell.FormulaR1C1 = "=IF(RC[-1]=""PO"",RC,IF(RC[-19]=R[-1]C[-19],R[-1]C,RC[1])"
Si aprés le bout de code qui nous interresse.
Dim COLIO, COLType As String
COLNotif = "W"
COLIO = "G"
COLType = "V"
vLastline = ActiveSheet.UsedRange.Rows.Count
Cells.Select
Selection.Sort Key1:=Range(COLIO & "2"), Order1:=xlAscending, Key2:= _
Range(COLType & "2"), Order2:=xlDescending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:= _
xlSortTextAsNumbers, DataOption2:=xlSortNormal
Columns(COLNotif & ":" & COLNotif).Select
Selection.Copy
Columns(COLNotif & ":" & COLNotif).Select
Selection.Insert Shift:=xlToRight
Range(COLNotif & "1").Select
ActiveCell.FormulaR1C1 = "PWO"
'Recherche et copie du PWO
Range(COLNotif & "2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]=""PO"",RC,IF(RC[-19]=R[-1]C[-19],R[-1]C,RC[1])"
Range(COLNotif & "2").Select
Selection.Copy
Range(COLNotif & "2:" & COLNotif & vLastline).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns(COLNotif & ":" & COLNotif).EntireColumn.AutoFit
Range(COLNotif & "2").Select
Application.CutCopyMode = False
Merci par avance de toutes assistance
Un débutant ...
Ca fait plusieurs jour que je cherche à encoder une formule IF sous VBA, pour un classeur Excel.
Je n'arrive pâs à encoder un if avec un autre if dans la formule suivante :
ActiveCell.FormulaR1C1 = "=IF(RC[-1]=""PO"",RC,IF(RC[-19]=R[-1]C[-19],R[-1]C,RC[1])"
Si aprés le bout de code qui nous interresse.
Dim COLIO, COLType As String
COLNotif = "W"
COLIO = "G"
COLType = "V"
vLastline = ActiveSheet.UsedRange.Rows.Count
Cells.Select
Selection.Sort Key1:=Range(COLIO & "2"), Order1:=xlAscending, Key2:= _
Range(COLType & "2"), Order2:=xlDescending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:= _
xlSortTextAsNumbers, DataOption2:=xlSortNormal
Columns(COLNotif & ":" & COLNotif).Select
Selection.Copy
Columns(COLNotif & ":" & COLNotif).Select
Selection.Insert Shift:=xlToRight
Range(COLNotif & "1").Select
ActiveCell.FormulaR1C1 = "PWO"
'Recherche et copie du PWO
Range(COLNotif & "2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]=""PO"",RC,IF(RC[-19]=R[-1]C[-19],R[-1]C,RC[1])"
Range(COLNotif & "2").Select
Selection.Copy
Range(COLNotif & "2:" & COLNotif & vLastline).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns(COLNotif & ":" & COLNotif).EntireColumn.AutoFit
Range(COLNotif & "2").Select
Application.CutCopyMode = False
Merci par avance de toutes assistance
Un débutant ...
A voir également:
- Programation formule en VBA
- Formule si et - Guide
- Excel mise en forme conditionnelle formule - Guide
- Formule moyenne excel plusieurs colonnes - Guide
- Formule mathématique - Télécharger - Études & Formations
- Formule somme excel colonne - Guide
1 réponse
bonjour
lorsque tu envoies un code met le entre les <> du bouton droit au dessus de ton message
Merci
en regardant en biais, il te manque une parenthèse à la fin de ta formle: compte les ( et les ) tu verras
et au passage il faut déclarer le type des variables, variable par variable
"Dim COLIO, COLType As String " colio est ainsi du type variant
donc
pour apprendre VBA:
https://bidou.developpez.com/article/VBA/
lorsque tu envoies un code met le entre les <> du bouton droit au dessus de ton message
Merci
en regardant en biais, il te manque une parenthèse à la fin de ta formle: compte les ( et les ) tu verras
et au passage il faut déclarer le type des variables, variable par variable
"Dim COLIO, COLType As String " colio est ainsi du type variant
donc
Dim COLIO as string, COLType As String, Colnotif as string
pour apprendre VBA:
https://bidou.developpez.com/article/VBA/
Akka_31
Merci, pour votre analyse la formule fonctionne dés à présent.