VBA, tô viềng trong Excel

Liên hệ QC

be_09

Biên Hòa, Đồng Nai
Tham gia
9/4/11
Bài viết
9,975
Được thích
9,860
Nghề nghiệp
Công chức
Nhận thấy nhiều thành viên hay nhắc đến việc tô viềng cho 1 bảng và nhất là có 1 số thành viên lại nêu "khi Record macro thì sao ra 1 đống code không biết sửa thế nào cho phù hợp".

Hôm nay, tôi tập hợp một số code tô viềng để các thành viên áp dụng cho File của mình được thuận tiện và phù hợp hơn. Xin mời tham khảo một số code sau (xem File đính kèm).

Mã:
Option Explicit
Sub Xoa_Vieng()
    Sheet1.Range("A3").CurrentRegion.Borders.ColorIndex = xlNone
End Sub
Sub ToVieng_QuanhDulieu()
    Sheet1.Range("A3").CurrentRegion.Borders.ColorIndex = xlNone
    Sheet1.Range("A3").CurrentRegion.BorderAround xlContinuous, xlThick
End Sub
Sub ToVieng_TatCa()
    Sheet1.Range("A3").CurrentRegion.Borders.ColorIndex = xlNone
'    Sheet1.Range("A3").CurrentRegion.Borders.Color = RGB(255, 0, 255) 'Màu tím
    Sheet1.Range("A3").CurrentRegion.Borders.ColorIndex = 38 'Màu tím
    Sheet1.Range("A3").CurrentRegion.BorderAround xlContinuous, xlThick
End Sub
Sub ToVieng_TaCa_Cells()
    Sheet1.Range("A3").CurrentRegion.Borders.ColorIndex = xlNone
    Sheet1.Range("A3").CurrentRegion.Borders.ColorIndex = 56 'Màu Den
    Sheet1.Range("A3").CurrentRegion.Borders.LineStyle = xlContinuous 'Màu Den
End Sub
Sub ToVieng_TaCa_Cells_Dam()
    Sheet1.Range("A3").CurrentRegion.Borders.ColorIndex = xlNone
    Sheet1.Range("A3").CurrentRegion.Borders.Weight = xlMedium 'Màu Den dâm (Bold)
End Sub
Sub NetDutVaViengDam()
     With Worksheets("Sheet1")
        .Range("A3").CurrentRegion.Borders.ColorIndex = xlNone
        .Range("A3:H3").Borders.Weight = xlMedium
        .Range("A3").CurrentRegion.Offset(1).Borders.LineStyle = xlThin
        .Range("A3").CurrentRegion.BorderAround xlContinuous, xlThick
    End With
End Sub
Sub GachNgatTrang()
    Dim i As Long
    Sheet1.Range("A3").CurrentRegion.Borders.ColorIndex = xlNone
    Sheet1.Range("A3").CurrentRegion.Borders.LineStyle = xlContinuous
    ActiveWindow.View = xlPageBreakPreview
    For i = 1 To ActiveSheet.HPageBreaks.Count
        With ActiveSheet.HPageBreaks(i).Location.Offset(-1).Columns("A:H").Borders(xlEdgeBottom)
            .LineStyle = xlContinuous: .Weight = xlThick: .ColorIndex = xlAutomatic
        End With
    Next
    ActiveWindow.View = xlNormalView
End Sub

A_Tovieng.GIF
 

File đính kèm

  • Tô viềng.xlsm
    25.7 KB · Đọc: 24
Web KT
Back
Top Bottom