BUY EXCEL BOOKS ONLINE: 1. VBA & Macros      2. VBA for Modelers      3. Excel 2013 VBA and Macros     
4. Excel VBA for Dummies      5. Excel with VBA & .NET      6. Mastering VBA      7. Excel 2013 Programming

Show Grid on Colored Range (Apply Border)

Whenever we apply background color to a range in Excel, we lost our gridlines. This macro, which is just a trick by applying colored border to the range will make it different i.e. Colored Range with Grid Lines. For eg. see the image below:






Sub Show_Grid_on_Color_Range()
   With Selection
      Selection.BorderAround xlContinuous, xlThin, , RGB(192, 192, 192)
      If .Columns.Count> 1 Then
         With .Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .Color = RGB(192, 192, 192)
         End With
      End If
      If
.Rows.Count> 1 Then
         With
.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .Color = RGB(192, 192, 192)
         End With
      End If
   End With
End Sub