macro ecrire formule dans cellule vide

tactic6

XLDnaute Impliqué
Bonjour le forum

je souhaiterai écrire une formule dans une série de cellules vides
j'ai donc écris ceci
Code:
Sub Macro7()
        If Range("C15") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B15));RECHERCHEV(B15;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C16") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B16));RECHERCHEV(B16;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C17") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B17));RECHERCHEV(B17;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C18") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B18));RECHERCHEV(B18;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C19") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B19));RECHERCHEV(B19;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C20") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B20));RECHERCHEV(B20;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C21") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B21));RECHERCHEV(B21;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C22") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B22));RECHERCHEV(B22;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C23") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B23));RECHERCHEV(B23;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C24") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B24));RECHERCHEV(B24;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C25") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B25));RECHERCHEV(B25;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C26") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B26));RECHERCHEV(B26;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C27") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B27));RECHERCHEV(B27;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C28") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B28));RECHERCHEV(B28;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C29") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B29));RECHERCHEV(B29;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C30") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B30));RECHERCHEV(B30;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
       End If
        If Range("C31") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B31));RECHERCHEV(B31;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
       End If
        If Range("C32") = "" Then
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B32));RECHERCHEV(B32;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C33") = "" Then
       
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B33));RECHERCHEV(B33;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C34") = "" Then
        
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B34));RECHERCHEV(B34;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C35") = "" Then
        
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B35));RECHERCHEV(B35;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
        If Range("C36") = "" Then
       
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B36));RECHERCHEV(B36;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
       End If
        If Range("C37") = "" Then
        
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B37));RECHERCHEV(B37;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
       End If
        If Range("C38") = "" Then
       
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B38));RECHERCHEV(B38;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
       End If
        If Range("C39") = "" Then
        
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B39));RECHERCHEV(B39;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
       End If
        If Range("C40") = "" Then
        
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B40));RECHERCHEV(B40;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
       End If
        If Range("C41") = "" Then
        
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B41));RECHERCHEV(B41;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
       End If
        If Range("C42") = "" Then
       
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B42));RECHERCHEV(B42;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
       End If
        If Range("C43") = "" Then
        
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B43));RECHERCHEV(B43;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If

        If Range("C44") = "" Then 
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B44));RECHERCHEV(B44;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If

        If Range("C45") = "" Then        
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B45));RECHERCHEV(B45;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
       End If
        
If Range("C46") = "" Then        
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B46));RECHERCHEV(B46;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
       End If
      
 If Range("C47") = "" Then       
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B47));RECHERCHEV(B47;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
       End If
     
 If Range("C48") = "" Then       
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B48));RECHERCHEV(B48;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If

        If Range("C49") = "" Then     
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B49));RECHERCHEV(B49;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
       End If

        If Range("C50") = "" Then       
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B50));RECHERCHEV(B50;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
       End If

        If Range("C51") = "" Then
                ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B51));RECHERCHEV(B51;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
       End If

        If Range("C52") = "" Then       
        ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B52));RECHERCHEV(B52;'liste des articles'!$A$2:$D$10000;2;FAUX);"") "
        End If
       
End Sub

La macro a pour but de sélectionner toutes les cellules vides de la colonne C à partir de C15 jusqu'à C52 et d'y écrire la formule qui y correspond

Malheureusement dès que la macro trouve une cellule vide j'ai une erreur d'exécution 1004
erreur définie par l'application ou par l'objet

quelqu'un peut m'aider ?
Merci
 

SubEndSub

XLDnaute Occasionnel
Re : macro ecrire formule dans cellule vide

Bonjour chez vous


Voici une possibilité

Code:
Sub macro()
Dim cellules As Range, formules As String
Set cellules = Range("C15:C52").SpecialCells(xlCellTypeBlanks)
formules = "=SI(NON(ESTVIDE(B15));RECHERCHEV(B15;'liste des articles'!$A$2:$D$10000;2;FAUX);"""") "
cellules.FormulaLocal = formules
End Sub
 

kjin

XLDnaute Barbatruc
Re : macro ecrire formule dans cellule vide

Bonjour,
Code:
Sub Macro7()
For i = 15 To 42
        If IsEmpty(Cells(i, 3)) Then
        Cells(i, 3).FormulaLocal = "=SI(NON(ESTVIDE(B" & i & "));RECHERCHEV(B" & i & ";'liste des articles'!$A$2:$D$10000;2;FAUX);"""")"
        End If
Next
End Sub
A+
kjin
 

job75

XLDnaute Barbatruc
Re : macro ecrire formule dans cellule vide

Bonjour tactic6, le forum,

Dans une formule entre guillemets, les guillemets doivent toujours être doublés :

Code:
ActiveCell.FormulaLocal = "=SI(NON(ESTVIDE(B15));RECHERCHEV(B15;'liste des articles'!$A$2:$D$10000;2;FAUX);[COLOR="Red"][SIZE="3"]""""[/SIZE][/COLOR])"

Par ailleurs vous savez faire une boucle ? Cela évite des répétitions de lignes bien laborieuses...

Edit : pas rafraîchi, il y a du monde que je salue !

A+
 

tactic6

XLDnaute Impliqué
Re : macro ecrire formule dans cellule vide

Merci a tous de vos réponses
job75 je suis tres limité en prog
j'arrive tant bien que mal a bidouiller des morceaux de codes faits par les forumeurs que je remercie encore et toujours


EDIT
je viens de faire un essai
c'est rapide et excelentissime
encore merci
 
Dernière édition:

Statistiques des forums

Discussions
312 232
Messages
2 086 461
Membres
103 220
dernier inscrit
samira2024