• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

TO change gridlinecolor line randomly on pressing button

Hi all,
i want to change my gridlinecolor everytime when i press the change color button . so please suggest me a suitable macro which can resolve my issue.
 
Add the following to a VBA Code Module

Code:
Sub Change_Gridline_Color()
Dim Red As Integer, Green As Integer, Blue As Integer
Dim Color As Long

Red = Int((255 - 0 + 1) * Rnd + 0)
Green = Int((255 - 0 + 1) * Rnd + 0)
Blue = Int((255 - 0 + 1) * Rnd + 0)

Color = RGB(Red, Green, Blue)

With Selection
  With .Borders(xlEdgeLeft)
  .LineStyle = xlContinuous
  .Color = Color
  .Weight = xlThin
  End With
  With .Borders(xlEdgeTop)
  .LineStyle = xlContinuous
  .Color = Color
  .Weight = xlThin
  End With
  With .Borders(xlEdgeBottom)
  .LineStyle = xlContinuous
  .Color = Color
  .Weight = xlThin
  End With
  With .Borders(xlEdgeRight)
  .LineStyle = xlContinuous
  .Color = Color
  .Weight = xlThin
  End With
  With .Borders(xlInsideVertical)
  .LineStyle = xlContinuous
  .Color = Color
  .Weight = xlThin
  End With
  With .Borders(xlInsideHorizontal)
  .LineStyle = xlContinuous
  .Color = Color
  .Weight = xlThin
  End With
End With

End Sub

To use Select an area
Run the code
 
If you want to change a specific range

change the With Selection line to:

Code:
With Range("A1:M100") 'Change range to suit
 
Back
Top