Programation formule en VBA

Résolu/Fermé
Akka_31 - 5 juil. 2011 à 08:35
 Akka_31 - 6 juil. 2011 à 10:18
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 ...
A voir également:

1 réponse

michel_m Messages postés 16603 Date d'inscription lundi 12 septembre 2005 Statut Contributeur Dernière intervention 16 décembre 2023 3 303
5 juil. 2011 à 08:51
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
Dim COLIO as string, COLType As String, Colnotif as string


pour apprendre VBA:
https://bidou.developpez.com/article/VBA/
1
Merci, pour votre analyse la formule fonctionne dés à présent.
0