Mise en page automatique des lignes non-vides
j
Bonjour à tous, re-bonjour à ceux/celles qui m'ont déjà aidé.
Je reviens vers vous rapidement pour un petit soucis. J'ai un tableau excel qui se remplie via un formulaire. Les données remplies viennent s'ajouter les unes à la suite des autres.
J'aimerais intégrer la chose suivante :
Dès qu'une ligne se remplie, la faire se mettre en page automatiquement.
J'arrive à mettre en page via macro un tableau fixe, mais je n'arrive pas à mettre en page ligne par ligne.
J'espère que ma question est claire, sinon, n'hésitez pas à me le faire savoir.
Private Sub CmdbuttonValider_Click()
Dim num As Long
' pout la dimension, les bugs etc
Sheets("Recherche foncière").Activate
' mettre ça au début
num = Sheets("Recherche foncière").Range("C65536").End(xlUp).Row + 1
' pour aller à la premiere ligne vide
Range("C" & num).Value = Txtcommune
Range("D" & num).Value = Txtadresse
Range("E" & num).Value = CbbAffectation
Range("F" & num).Value = CBBpréexistante
Range("G" & num).Value = TxtPLQ
Range("H" & num).Value = Txtproduit
Range("I" & num).Value = Txtnumparcelle
If Txtsurface = "" Then
Range("J" & num).Value = 0
Else
Range("J" & num).Value = CDbl(Replace(Txtsurface, ".", ","))
End If
If Ttxpotentiel = "" Then
Range("K" & num).Value = 0
Else
Range("K" & num).Value = CDbl(Replace(Txtpotentiel, ".", ","))
End If
' IIF = "" pour dire que si c'est vide, il ne met rien
' CDbl... pour dire que c'est au format numérique (et non en texte) pour faire des formules
Range("L" & num).Value = Txtactions
Range("M" & num).Value = Txtpersonnedossier
If OptionButton1.Value = True Then Range("B" & num) = ("Court terme")
If OptionButton2.Value = True Then Range("B" & num) = ("Moyen terme")
If OptionButton3.Value = True Then Range("B" & num) = ("Long terme")
Unload Me
'pour fermer l'userform après avoir cliqué sur validé
Range("B2").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=B2=""Court terme"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 8033810
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=B2=""Moyen terme"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 52479
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=B2=""Long terme"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
ActiveWindow.SmallScroll Down:=-24
'Pour la mise en forme conditionnelle
j
J'ai cela comme code de mise en page mais je n'arrive pas à l'appliquer pour la ligne que je suis en train de remplir avec mon userform.
Range("P6:T6").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlEdgeTop).LineStyle = xlNone
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDot
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
j
Voici la solution que j'ai trouvé pour celles et ceux que ça intéresse :
Truc = Range("B6:T" & [C65536].End(xlUp).Row).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlDash
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDash
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlDash
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With