Formule dans cellule Vba

Résolu
Bonjour Le forum
voila je voudrais insérer une formule dans une cellule.
Cells(5, 2).FormulaLocal = "='sheets("Janvier " +rep)'!R[3]C[27]"

sachant que "rep" est une variable
avez vous une idée de correction s'il vous plait :)
Merci

6 réponses

  • Votes
  • Date
  • Date décroissante
  1. Bonjour M-12
    merci pour ton aide
    il me met toujours demande fin d'instruction;(
    1. Voila mon code en question et le problème est a la fin quand je souhaites entrer une formule dans une cellule
      Sub Creation_Calendrier()
      Dim rep As Variant
      Dim chemin As String
      Dim Mois As String
      rep = InputBox("Quelle année d'exercice?")
      cemin = "C:\Users\Sandrine\Desktop\PERSO\SOCIETE\Suivi SJTC"
      Worksheets(Array("Consolidé", "Facturation")).Copy
      ActiveWorkbook.SaveAs Filename:=cemin & "\Exercice SJT-C " & rep & ".xls", FileFormat:=52
      Workbooks("Exercice SJT-C " + rep).Worksheets("Consolidé").Activate

      Cells(2, 2).Value = "Janvier " + rep
      Cells(2, 6).Value = "Fevrier " + rep
      Cells(2, 10).Value = "Mars " + rep
      Cells(2, 14).Value = "Avril " + rep
      Cells(2, 18).Value = "Mai " + rep
      Cells(2, 22).Value = "Juin " + rep
      Cells(2, 26).Value = "Juillet " + rep
      Cells(2, 30).Value = "Aout " + rep
      Cells(2, 34).Value = "Septembre " + rep
      Cells(2, 38).Value = "Octobre " + rep
      Cells(2, 42).Value = "Novembre " + rep
      Cells(2, 46).Value = "Décembre " + rep
      Cells(2, 50).Value = "Totaux " + rep
      Mois = Cells(2, 2).Value
      Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Janvier " + rep
      With Sheets("janvier " + rep)
      Call conception_feuille
      End With
      Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Fevrier " + rep
      With Sheets("Fevrier " + rep)
      Call conception_feuille
      End With
      Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Mars " + rep
      With Sheets("Mars " + rep)
      Call conception_feuille
      End With
      Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Avril " + rep
      With Sheets("Avril " + rep)
      Call conception_feuille
      End With
      Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Mai " + rep
      With Sheets("Mai " + rep)
      Call conception_feuille
      End With
      Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Juin " + rep
      With Sheets("Juin " + rep)
      Call conception_feuille
      End With
      Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Juillet " + rep
      With Sheets("Juillet " + rep)
      Call conception_feuille
      End With
      Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Aout " + rep
      With Sheets("Aout " + rep)
      Call conception_feuille
      End With
      Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Septembre " + rep
      With Sheets("Septembre " + rep)
      Call conception_feuille
      End With
      Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Octobre " + rep
      With Sheets("Octobre " + rep)
      Call conception_feuille
      End With
      Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Novembre " + rep
      With Sheets("Novembre " + rep)
      Call conception_feuille
      End With
      Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Décembre " + rep
      With Sheets("Décembre " + rep)
      Call conception_feuille
      End With
      Sheets("Consolidé").Select
      'Cells(5, 2).FormulaLocal = "='sheets(Janvier "& rep")'!R[3]C[27]"

      ChDir "C:\Users\Sandrine\Desktop\PERSO\SOCIETE\Suivi SJTC"
      End Sub
      1. Bonjour

        Essaies en découpant un peu
        Dim mois As String
        Dim rep As Long
        Dim f As String
        rep = 2021
        mois = "Janvier"
        f = "='" & mois & "-" & rep & "'!R[3]C[27]"
        Cells(5, 2).Formula = f


        Cdlmnt
        1. Bonjour ccm81
          je te remercie pour ton aide
          je me suis inspiré de ton code et j'ai refais ceci.
          Avec ta solution cela devait mettre des variables différentes pour chaque mois ;)
          an tout cas cela fonctionne bien et merci beaucoup
          belle journée
          Sheets("Consolidé").Select

          Cells(5, 2).Formula = "='" & MonthName(1) & " " & rep & "'!R[3]C[27]"
          Cells(5, 3).Formula = "='" & MonthName(1) & " " & rep & "'!R[3]C[27]"
          Cells(5, 4).Formula = "='" & MonthName(1) & " " & rep & "'!R[3]C[27]"