MrExcel Publishing
Your One Stop for Excel Tips & Solutions

changing cell color but not border

Posted by john on January 27, 2002 1:24 PM

I would like to change the cell color on a particuluar cell, but leave the border properties the same. Is there a way a of doing this? If not, how can I restore the border properties of a cell to the standard excel default in VBA?


Posted by Robb on January 27, 2002 2:35 PM


I'm not sure whether you want to make the color change manually or by code. To make the change manually:

- Selct the cell(s) for which you want a color change
- From the Format menu, select Cells
- Select the Patterns tab
- Select a color

If you are wanting to do it with code, try this (it will set the interior color to red):

Sub CellColor()
With Worksheets("Sheet1").Range("A1")
.Interior.Color = RGB(255, 0, 0)
End With

End Sub

To change the border back to default, try this:

Sub RemoveCellBorder()
With Worksheets("Sheet1").Range("A1")
.Borders.LineStyle = xlLineStyleNone
End With

End Sub

Any help?