Notifications
Clear all

Como aplicar bordas de acordo com uma condição

2 Posts
1 Usuários
0 Reactions
1,341 Visualizações
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Bom dia.
Estou criando uma planilha e aplicando umas condições para deixá-la com um visual mais bacana e limpo. Gostaria de criar uma condição para uma certa quantidade linhas, esta condição seria da seguinte forma:
-Quando o campo “C9” fosse preenchido, a linha “C9:O9” aplicasse uma borda em todas as células da linha. Só que esta condição tem que ser aplicada nas linha que vem em seqüência conforme fosse preenchidos os seus campos iniciais (Ex.: “C10:O10” , “C11:O11” e assim por diante).
Segue o código que eu acho que funcionaria para uma linha:

Sub BORDERS()

Range("C9:O9").Select
Selection.BORDERS(xlDiagonalDown).LineStyle = xlNone
Selection.BORDERS(xlDiagonalUp).LineStyle = xlNone
With Selection.BORDERS(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With Selection.BORDERS(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With Selection.BORDERS(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With Selection.BORDERS(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
End Sub

Se estiver certo, com fazê-lo entrar na condição descrita a cima?
Desde já muito obrigado a todos.

 
Postado : 23/09/2010 7:47 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 


Veja se é isso:

Na planilha:


Private Sub Worksheet_Change(ByVal Target As Range)
lin = Target.Row
col = Target.Column

If col <> 3 Then
Exit Sub
ElseIf lin < 9 Then
Exit Sub
Else
n = lin
Call BORDERS(n)
End If

End Sub


Num Módulo:

Sub BORDERS(n)

Range("C" & n & ":O" & n).Select

With Selection.BORDERS(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With Selection.BORDERS(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With Selection.BORDERS(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With
With Selection.BORDERS(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = xlAutomatic
End With

Range("C" & n + 1).Select

End Sub

 
Postado : 29/10/2010 9:48 pm