M
matiousky
Guest
Bonjour,
J'ai créé un code et je voudrai que celui-ci s'execute si et seulement si deux conditions sont respectées.
Cependant malgré mon code cela ne marche pas. Pouvez-vous m'aider ?
Merci,
Mat.
Voici les deux conditions
If Range("D170") <> Range("N4") Then MsgBox "Attention votre profil est différent de celui selecionné": ok = False
If Range("M12").Value <> 1 Then MsgBox "L'impression de la synthèse client est impossible car vous n'êtes pas à 100% investi": ok = False
Voici le code que j'ai constitué, incluant les deux conditions:
Dim ok As Boolean
ok = True
If Range("D170") <> Range("N4") Then MsgBox "Attention votre profil est différent de celui selecionné": ok = False
If Range("M12").Value <> 1 Then MsgBox "L'impression de la synthèse client est impossible car vous n'êtes pas à 100% investi": ok = False
Application.ScreenUpdating = False
Sheets("Synthèse client").Visible = True
Sheets("Synthèse client").PivotTables("Tableau croisé dynamique1").PivotCache.Refresh
Sheets("Synthèse client").Select
Range("H12:J39").Select
Selection.ClearContents
Range("M14:O39").Select
Selection.Copy
Range("H14").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("H14:J39").Select
Selection.Font.Bold = False
Selection.Font.Italic = False
Selection.Font.Underline = xlUnderlineStyleSingle
Selection.Font.Underline = xlUnderlineStyleNone
With Selection.Font
.Name = "Arial"
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
End With
Selection.Font.ColorIndex = 49
With Selection.Font
.Name = "Arial"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 49
End With
Range("H12").Select
ActiveCell.FormulaR1C1 = "FONDS"
Range("I12").Select
ActiveCell.FormulaR1C1 = "MONTANT EN EUR"
Range("J12").Select
ActiveCell.FormulaR1C1 = "%"
Range("H13:J37").Select
Selection.Sort Key1:=Range("j:j"), Order1:=xlDescending, Key2:=Range( _
"h:h"), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase _
:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal
Sheets("Synthèse client").Select
Range("H12:J12").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With
If ok Then
Range("T4:U9").EntireRow.Hidden = False
For Each sel In Range("H4:I9")
If sel = "" Then sel.EntireRow.Hidden = True
Next
ActiveSheet.ChartObjects("Graphique 6").Activate
ActiveChart.ChartArea.Select
With ActiveChart
.DisplayBlanksAs = xlNotPlotted
.PlotVisibleOnly = False
.SizeWithWindow = True
End With
Application.ShowChartTipNames = True
Application.ShowChartTipValues = True
With ActiveChart
.DisplayBlanksAs = xlNotPlotted
.PlotVisibleOnly = True
.SizeWithWindow = True
End With
Application.ShowChartTipNames = True
Application.ShowChartTipValues = True
Application.ScreenUpdating = True
Range("B1").Select
Sheets("Synthèse client").PrintOut Copies:=1
Sheets("Synthèse client").Visible = False
End If
End Sub
J'ai créé un code et je voudrai que celui-ci s'execute si et seulement si deux conditions sont respectées.
Cependant malgré mon code cela ne marche pas. Pouvez-vous m'aider ?
Merci,
Mat.
Voici les deux conditions
If Range("D170") <> Range("N4") Then MsgBox "Attention votre profil est différent de celui selecionné": ok = False
If Range("M12").Value <> 1 Then MsgBox "L'impression de la synthèse client est impossible car vous n'êtes pas à 100% investi": ok = False
Voici le code que j'ai constitué, incluant les deux conditions:
Dim ok As Boolean
ok = True
If Range("D170") <> Range("N4") Then MsgBox "Attention votre profil est différent de celui selecionné": ok = False
If Range("M12").Value <> 1 Then MsgBox "L'impression de la synthèse client est impossible car vous n'êtes pas à 100% investi": ok = False
Application.ScreenUpdating = False
Sheets("Synthèse client").Visible = True
Sheets("Synthèse client").PivotTables("Tableau croisé dynamique1").PivotCache.Refresh
Sheets("Synthèse client").Select
Range("H12:J39").Select
Selection.ClearContents
Range("M14:O39").Select
Selection.Copy
Range("H14").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("H14:J39").Select
Selection.Font.Bold = False
Selection.Font.Italic = False
Selection.Font.Underline = xlUnderlineStyleSingle
Selection.Font.Underline = xlUnderlineStyleNone
With Selection.Font
.Name = "Arial"
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
End With
Selection.Font.ColorIndex = 49
With Selection.Font
.Name = "Arial"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 49
End With
Range("H12").Select
ActiveCell.FormulaR1C1 = "FONDS"
Range("I12").Select
ActiveCell.FormulaR1C1 = "MONTANT EN EUR"
Range("J12").Select
ActiveCell.FormulaR1C1 = "%"
Range("H13:J37").Select
Selection.Sort Key1:=Range("j:j"), Order1:=xlDescending, Key2:=Range( _
"h:h"), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase _
:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal
Sheets("Synthèse client").Select
Range("H12:J12").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With
If ok Then
Range("T4:U9").EntireRow.Hidden = False
For Each sel In Range("H4:I9")
If sel = "" Then sel.EntireRow.Hidden = True
Next
ActiveSheet.ChartObjects("Graphique 6").Activate
ActiveChart.ChartArea.Select
With ActiveChart
.DisplayBlanksAs = xlNotPlotted
.PlotVisibleOnly = False
.SizeWithWindow = True
End With
Application.ShowChartTipNames = True
Application.ShowChartTipValues = True
With ActiveChart
.DisplayBlanksAs = xlNotPlotted
.PlotVisibleOnly = True
.SizeWithWindow = True
End With
Application.ShowChartTipNames = True
Application.ShowChartTipValues = True
Application.ScreenUpdating = True
Range("B1").Select
Sheets("Synthèse client").PrintOut Copies:=1
Sheets("Synthèse client").Visible = False
End If
End Sub