Tempo de leitura: 1 minuto
Bordas Excel VBA inserir em intervalos de células usadas
Com esses Macros (rotinas e subrotinas) vamos aprender como inserir borda em determinado range. Observe que temos uma função Gera_Entre que corresponde a WorkshetFunction AleatorioEntre, que vai gerar números nesse intervalo de números inseridos.
Sub Inserindo_bordas_range()
Dim sbCelula As Range
Range(“L1”).Formula = “=GERA_ENTRE(1,56)”
X = 3
Y = 5
For Each sbCelula In Range(“A” & X & “:P” & Y)
Call Inserir_Bordas(sbCelula)
sbCelula.Value = “SaberExcel”
sbCelula.Font.Size = 8
sbCelula.Font.ColorIndex = [L1].Value ‘16776961
[E8].Font.ColorIndex = [L1].Value
[L1].Font.ColorIndex = [L1].Value
Next sbCelula
‘Range(“g19”).Characters(Start:=19, Length:=7).Font.ColorIndex = [L1].Value
End Sub
‘—————‘
Sub Inserir_Bordas(sbCelula As Range)
sbCelula.Borders(xlEdgeLeft).LineStyle = xlContinuous
‘sbCelula.Borders(xlEdgeTop).LineStyle = xlNone ‘essa linha de código não insere bordas
sbCelula.Borders(xlEdgeTop).Color = -4165632
sbCelula.Borders(xlEdgeBottom).LineStyle = xlContinuous
sbCelula.Borders(xlEdgeRight).LineStyle = xlContinuous
sbCelula.Borders(xlEdgeRight).Color = -16776961
End Sub
‘Observe que usamos a mesma macro acima, porém mudamos o nome
‘vai rodas todas as células, o macro vai deletá-las.
Sub Limpar_celulas_teste()
Dim sbCelula As Range
X = 3 :Y = 5
For Each sbCelula In Range(“A” & X & “:P” & Y)
‘ Call Inserir_Bordas(sbCelula)
sbCelula.Clear
Next sbCelula
End Sub
Função Personalizada AleatorioEntre = RandBetWeen()
Function GERA_ENTRE(Limite_inferior, Limite_superior)
GERA_ENTRE = Limite_inferior + Int(Rnd() * (Limite_superior – Limite_inferior))
End Function
promoção!!!
Compre todo Material didático Escola SaberExcel VBA Estudos.