Sunday, January 13, 2019

VBA Border dan Interior Color Otomatis








Membuat Border dan Warna Baris berdasarkan NO urut Genap Ganjil
Caranya cukup Mudah Pastekan Kode berikut pada sebuah worksheet

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'asanaputu@gmail.com
'Raha,14 Januri 2019
'============================================
Dim Row, Col As Long
Dim x, Warna As Range

'membuat no urut otomatis

Range("a6:a50").Value = ""
ActiveSheet.Range("a1") = Application.CountA(Range("B6:B100"))
    No = 0
For NOMOR = 1 To Range("a1")
No = No + 1
Cells(No + 5, 1).Value = No
Next NOMOR

'Border sesuai cell yang terisi
  Cells.Borders.LineStyle = xlNone
  Row = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
  Col = Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column
  With Range("A5", Cells(Row, Col))
    .BorderAround xlDouble
    .Rows.Borders(xlInsideHorizontal).LineStyle = xlDash
    .Rows.Borders(xlInsideVertical).LineStyle = xlContinuous
  End With
 
'mewarnai no urut ganjil

Set Warna = Range("a6:a50")
For Each cell In Warna
            If cell Mod 2 Then
        cell.Interior.ColorIndex = 15
         Else
        cell.Interior.ColorIndex = 2
       End If
         Next cell

   ‘Copy Warna Kolom A ke B sampai G  

For Each x In Range("a2:a200")
          Range("b" & x.Row).Interior.Color = x.Interior.Color
         Range("c" & x.Row).Interior.Color = x.Interior.Color
          Range("d" & x.Row).Interior.Color = x.Interior.Color
           Range("e" & x.Row).Interior.Color = x.Interior.Color
            Range("f" & x.Row).Interior.Color = x.Interior.Color
            Range("G" & x.Row).Interior.Color = x.Interior.Color
    Next x
End Sub





No comments:

Post a Comment

APLIKASI GUDANG VERSI EXCEL VBA

Aplikasi Gudang Sederhana silahkan dikembangkan kritik dan saran membangun selalu kami harapkan FROM ENTRI IURAN BULANA...