|
|
|
|
Bonjour,
j'ai fais une marco Excel et je cherche à insérer dans certaines colonnes de mon tableau une formule de calcul style:
=SI(ET(ESTVIDE(C7);ESTVIDE(B7));"";SI(B7="";C7;SI(C7="";-B7;C7-B7)))
comment faire pour la traduire en vba? faut il tout traduire, pas à pas la formule où il y a t-il une façon plus simple et plus directe?
Merci d'avance,
Nta
Bonjour,
Sub InsereFormule()
Dim Formule As String
' [ =SI(ET(ESTVIDE(C7);ESTVIDE(B7));"";SI(B7="";C7;SI(C7="";-B7;C7-B7))) ]
' [ "=IF(AND(ISBLANK(R[4]C[1]),ISBLANK(R[4]C)),"""",IF(R[4]C="""",R[4]C[1],IF(R[4]C[1]="""",-R[4]C,R[4]C[1]-R[4]C)))" ]
Formule = "=IF(AND(ISBLANK(C7),ISBLANK(B7)),"
Formule = Formule & """" & """" & ",IF(B7=" & """" & """"
Formule = Formule & ",C7,IF(C7=" & """" & """" & ",-B7,C7-B7)))"
ActiveCell.Offset(0, 0).Value = Formule
End Sub
'
Lupin Configuration: Windows XP Internet Explorer 6.0 |
Bonjour,
Configuration: Windows XP Internet Explorer 7.0 |
Re :
Sub Copier()
Dim Col As Long, Rw As Long
For Col = 3 To ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column
For Rw = 5 To ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
If (Cells(Rw, Col).Value <> "") Then
Cells(Rw + 1, Col).Value = Cells(Rw, Col).Value
Cells(Rw, Col).Clear
End If
Next Rw
Next Col
End Sub
'
je n'ai pas saisie le pourquoi de :
Sub Copier2()
Dim Col As Long, Rw As Long
For Col = 3 To ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column
For Rw = 5 To ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
If (Cells(Rw, Col).Value <> "") Then
Cells(Rw + 1, Col).Value = Cells(Rw, Col).Value
Cells(Rw, Col).Clear
Rw = (Rw + 1) ' ???
Else: Rw = (Rw + 1) '???
End If
Next Rw
Next Col
End Sub
'
devrait se lire :
Sub Copier3()
Dim Col As Long, Rw As Long
For Col = 3 To ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column
For Rw = 5 To ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
If (Cells(Rw, Col).Value <> "") Then
Cells(Rw + 1, Col).Value = Cells(Rw, Col).Value
Cells(Rw, Col).Clear
Rw = (Rw + 1) ' ???
Else
Rw = (Rw + 1) '???
End If
Next Rw
Next Col
End Sub
'
ce qui est équivalent à :
Sub Copier4()
Dim Col As Long, Rw As Long
For Col = 3 To ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column
For Rw = 5 To ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
If (Cells(Rw, Col).Value <> "") Then
Cells(Rw + 1, Col).Value = Cells(Rw, Col).Value
Cells(Rw, Col).Clear
End If
Rw = (Rw + 1)
Next Rw
Next Col
End Sub
'
si vraiment la boucle [ For Rw = 5 to ... ] fonctionne, il n'est nul besoin d'incrémenter Rw par [ Rw = (Rw + 1) ]. Lupin Configuration: Windows XP Internet Explorer 6.0 |