Inserer une formule+Macro

Ch3ayba

XLDnaute Junior
Bonjour,

J'aimerai pouvoir inserer une formule dans mon fichier, les deux premieres partie de ma macro pour insérer et renomer les colonnes fonctionnent mais la derniere partie pour la formule non, je veux inserer une formule dans les cellules vides qui s'inserent (FCST ERROR) à savoir que les colonnes ne sont pas fixe.

Merci d'avance pour votre aide.

Pj : exemple.
 

Pièces jointes

  • Exemple4.zip
    6.2 KB · Affichages: 45
  • Exemple4.zip
    6.2 KB · Affichages: 44
  • Exemple4.zip
    6.2 KB · Affichages: 44

Efgé

XLDnaute Barbatruc
Re : Inserer une formule+Macro

Bonjour Ch3ayba,
Si j'ai bien compris, essayez comme ça :
Code:
Sub formul()
Dim i As Long
Dim j As Long
    For i = Range("IV6").End(xlToLeft).Column To 1 Step -1
        For j = Range("A65536").End(xlUp).Row To 1 Step -1
            If Cells(j, i) <> "" And Cells(j + 1, i) = "" Then
                Cells(j + 1, i).Value = Cells(j - 1, i).Value - Cells(j, i).Value
            End If
        Next j
    Next i
End Sub
Cordialement
 

Ch3ayba

XLDnaute Junior
Re : Inserer une formule+Macro

Bonjour Ch3ayba,
Si j'ai bien compris, essayez comme ça :
Code:
Sub formul()
Dim i As Long
Dim j As Long
    For i = Range("IV6").End(xlToLeft).Column To 1 Step -1
        For j = Range("A65536").End(xlUp).Row To 1 Step -1
            If Cells(j, i) <> "" And Cells(j + 1, i) = "" Then
                Cells(j + 1, i).Value = Cells(j - 1, i).Value - Cells(j, i).Value
            End If
        Next j
    Next i
End Sub
Cordialement


Merci Efgé pour ta réponse. j'ai essayé mais ça ne fonctionne pas ça me marque inompatibilité de type.

Cordialement.
 

Efgé

XLDnaute Barbatruc
Re : Inserer une formule+Macro

Re
J'espère avoir cerné ce que vous vouliez faire, mais je ne suis sûr de rien...
Peut être avec ça à la place de vos quatre sub :
Code:
Sub all_mac()
Dim i As Long
Dim j As Long
j = Range("A" & Application.Rows.Count).End(xlUp).Row + 1
    For i = Range("IV6").End(xlToLeft).Column To 1 Step -1
        If Cells(6, i) = "Sales Team Forecast" And Cells(6, i + 1) <> "" Then
            Columns(i + 1).Insert Shift:=xlToRight
            Cells(6, i + 1).Value = "Fcst Error"
        End If
        If Cells(j - 1, i) <> "" Then
            Cells(j, i).Value = Cells(j - 1, i).Value - Cells(j - 2, i).Value
        End If
    Next i
End Sub
Cordialement
 

Ch3ayba

XLDnaute Junior
Re : Inserer une formule+Macro

Merci efege pour tes reponse, je ne suis pas clair je crois, désolé,

Ce que je cherche c'est insérer dans la colonne qui fcst error la formule = demand history - forcast . comme ça quand j'excute ma macro mes cellules se remplissent en automatique.

j'ete parti sur un truc comme ça

Sub formul()
Dim i As Long
Dim j As Long
For i = Range("IV6").End(xlToLeft).Column To 6 Step -1
For j = Range("A65536").End(xlUp).Row To 1 Step -1
If Cells(j, i) <> "" And Cells(j, i + 1) = "" Then
Cells(j, i + 1).Value = cells(j, i-1).value – cells (j,i-2)
End If
Next j
Next i
End Sub


Qu'est ce que tu pourrais me suggérer par rapport à ca???

Merci d'avance.
 
Dernière édition:

Efgé

XLDnaute Barbatruc
Re : Inserer une formule+Macro

Re
Content que vous ayez trouvé, mais au cas ou....
Code:
Sub all_mac()
Dim i As Long
Dim j As Long
j = Range("A" & Application.Rows.Count).End(xlUp).Row
    For i = Range("IV6").End(xlToLeft).Column + 1 To 1 Step -1
        If Cells(6, i) = "Sales Team Forecast" Then
            Columns(i + 1).Insert Shift:=xlToRight
            Cells(6, i + 1).Value = "Fcst Error"
            sAdr = Cells(6, i + 1).Address(1, 0)
            Col = Mid(sAdr, 1, InStr(1, sAdr, "$") - 1)
            sAdr2 = Cells(7, i).Address(1, 0)
            Col2 = Mid(sAdr2, 1, InStr(1, sAdr2, "$") - 1)
            sAdr3 = Cells(7, i - 1).Address(1, 0)
            Col3 = Mid(sAdr3, 1, InStr(1, sAdr3, "$") - 1)
            Range(Col & "7:" & Col & Range("A65536").End(xlUp).Row).FormulaLocal = "=" & Col3 & "7 -" & Col2 & "7"
        End If
    Next i
End Sub
Cordialement
EDIT: Ajout du fichier exemple (macro dans le bouton)
 

Pièces jointes

  • Ch3ayba(2).zip
    13.3 KB · Affichages: 40
  • Ch3ayba(2).zip
    13.3 KB · Affichages: 38
  • Ch3ayba(2).zip
    13.3 KB · Affichages: 41
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
312 595
Messages
2 090 094
Membres
104 374
dernier inscrit
cheick.coulibaly@dcsmali.