OVH Cloud OVH Cloud

Copier - coller valeur dans macro

2 réponses
Avatar
François
Bonjour =E0 tous,

Ci joint une macro qui inscrit une formule dans une=20
cellule si la colonne A contient des infos.
Je n'arrive pas =E0 rajouter l'expression suivante : si=20
excel inscrit la formule, il faut, pour figer les valeurs,=20
qu'il copie - colle valeur avant de passer =E0 la cellule=20
suivante.
Merci pour votre aide,

Cordialement,

Fran=E7ois

Le code :
Sub Report()
Dim Cel As Range
Dim txt As Object
Dim Periode, Col

Periode =3D Sheets("Data").Range("AD1")
Col =3D Sheets("Data").Range("AD2")
For Each Cel In [A47:A66]
For Each txt In Cel
X =3D SplitFor97(txt, "-")
=20
For i =3D 1 To UBound(X)
laFormule =3D laFormule & "(NC=3D" & "" & X(i)=20
& "" & ")+"
Next i
=20
Next txt
On Error Resume Next
Cells(Cel.Row, Col) =3D "=3D-sumproduct((" & Left
(laFormule, Len(laFormule) - 1) & ")*" & Periode & ")"
=20
If Cells(Cel.Row, Col) =3D 0 Then
laFormule =3D ""
=20
ElseIf Cells(Cel.Row, Col) <> 0 Then
Cells(Cel.Row, Col) =3D "=3D-sumproduct((" & Left
(laFormule, Len(laFormule) - 1) & ")*" & Periode & ")-sum
(D" & Cel.Row & ":" & NomCol(Col - 1) & Cel.Row & ")"
laFormule =3D ""
=20
End If

Next Cel

End Sub

2 réponses

Avatar
Frédéric Sigonneau
Bonsoir,

Essaye avec cette modif (attention aux retours à la ligne intempestifs) :

'================ Sub Report()
Dim Cel As Range
Dim txt As Object
Dim Periode, Col

Periode = Sheets("Data").Range("AD1")
Col = Sheets("Data").Range("AD2")
For Each Cel In [A47:A66]
For Each txt In Cel
X = SplitFor97(txt, "-")
For i = 1 To UBound(X)
laFormule = laFormule & "(NC=" & "" & X(i) & "" & ")+"
Next i
Next txt
On Error Resume Next
Cells(Cel.Row, Col) = _
"=-sumproduct((" & Left(laFormule, Len(laFormule) - 1) & ")*" & Periode & ")"

If Cells(Cel.Row, Col) = 0 Then
laFormule = ""
ElseIf Cells(Cel.Row, Col) <> 0 Then
Cells(Cel.Row, Col) = _
"=-sumproduct((" & Left(laFormule, Len(laFormule) - 1) & ")*" & _
Periode & ")-sum(D" & Cel.Row & ":" & NomCol(Col - 1) & Cel.Row & ")"
laFormule = ""
End If
Cells(Cel.Row, Col).Value = Cells(Cel.Row, Col).Value 'modif ici
Next Cel
End Sub
'================
FS
---
Frédéric Sigonneau [MVP Excel - né un sans-culottide]
Gestions de temps, VBA pour Excel :
http://perso.wanadoo.fr/frederic.sigonneau
Si votre question sur Excel est urgente, évitez ma bal !


Bonjour à tous,

Ci joint une macro qui inscrit une formule dans une
cellule si la colonne A contient des infos.
Je n'arrive pas à rajouter l'expression suivante : si
excel inscrit la formule, il faut, pour figer les valeurs,
qu'il copie - colle valeur avant de passer à la cellule
suivante.
Merci pour votre aide,

Cordialement,

François

Le code :
Sub Report()
Dim Cel As Range
Dim txt As Object
Dim Periode, Col

Periode = Sheets("Data").Range("AD1")
Col = Sheets("Data").Range("AD2")
For Each Cel In [A47:A66]
For Each txt In Cel
X = SplitFor97(txt, "-")

For i = 1 To UBound(X)
laFormule = laFormule & "(NC=" & "" & X(i)
& "" & ")+"
Next i

Next txt
On Error Resume Next
Cells(Cel.Row, Col) = "=-sumproduct((" & Left
(laFormule, Len(laFormule) - 1) & ")*" & Periode & ")"

If Cells(Cel.Row, Col) = 0 Then
laFormule = ""

ElseIf Cells(Cel.Row, Col) <> 0 Then
Cells(Cel.Row, Col) = "=-sumproduct((" & Left
(laFormule, Len(laFormule) - 1) & ")*" & Periode & ")-sum
(D" & Cel.Row & ":" & NomCol(Col - 1) & Cel.Row & ")"
laFormule = ""

End If

Next Cel

End Sub



Avatar
François
Bonsoir Frédéric,

Parfait... Merci pour ton aide.

Bien cordialement,

François

-----Message d'origine-----
Bonsoir,

Essaye avec cette modif (attention aux retours à la ligne
intempestifs) :


'=================
Sub Report()
Dim Cel As Range
Dim txt As Object
Dim Periode, Col

Periode = Sheets("Data").Range("AD1")
Col = Sheets("Data").Range("AD2")
For Each Cel In [A47:A66]
For Each txt In Cel
X = SplitFor97(txt, "-")
For i = 1 To UBound(X)
laFormule = laFormule & "(NC=" & "" & X(i) & ""
& ")+"

Next i
Next txt
On Error Resume Next
Cells(Cel.Row, Col) = _
"=-sumproduct((" & Left(laFormule, Len(laFormule) -
1) & ")*" & Periode & ")"


If Cells(Cel.Row, Col) = 0 Then
laFormule = ""
ElseIf Cells(Cel.Row, Col) <> 0 Then
Cells(Cel.Row, Col) = _
"=-sumproduct((" & Left(laFormule, Len
(laFormule) - 1) & ")*" & _

Periode & ")-sum(D" & Cel.Row & ":" &
NomCol(Col - 1) & Cel.Row & ")"

laFormule = ""
End If
Cells(Cel.Row, Col).Value = Cells(Cel.Row,
Col).Value 'modif ici

Next Cel
End Sub
'=================

FS
---
Frédéric Sigonneau [MVP Excel - né un sans-culottide]
Gestions de temps, VBA pour Excel :
http://perso.wanadoo.fr/frederic.sigonneau
Si votre question sur Excel est urgente, évitez ma bal !


Bonjour à tous,

Ci joint une macro qui inscrit une formule dans une
cellule si la colonne A contient des infos.
Je n'arrive pas à rajouter l'expression suivante : si
excel inscrit la formule, il faut, pour figer les
valeurs,


qu'il copie - colle valeur avant de passer à la cellule
suivante.
Merci pour votre aide,

Cordialement,

François

Le code :
Sub Report()
Dim Cel As Range
Dim txt As Object
Dim Periode, Col

Periode = Sheets("Data").Range("AD1")
Col = Sheets("Data").Range("AD2")
For Each Cel In [A47:A66]
For Each txt In Cel
X = SplitFor97(txt, "-")

For i = 1 To UBound(X)
laFormule = laFormule & "(NC=" & "" & X
(i)


& "" & ")+"
Next i

Next txt
On Error Resume Next
Cells(Cel.Row, Col) = "=-sumproduct((" & Left
(laFormule, Len(laFormule) - 1) & ")*" & Periode & ")"

If Cells(Cel.Row, Col) = 0 Then
laFormule = ""

ElseIf Cells(Cel.Row, Col) <> 0 Then
Cells(Cel.Row, Col) = "=-sumproduct((" & Left
(laFormule, Len(laFormule) - 1) & ")*" & Periode & ")-
sum


(D" & Cel.Row & ":" & NomCol(Col - 1) & Cel.Row & ")"
laFormule = ""

End If

Next Cel

End Sub

.