PDA

View Full Version : changing color of cells with vba



ashgull80
09-03-2012, 11:03 AM
hi
i have this code which finds the first empty row then adds the data to the sheet. what im after then is to change the colour of the row from columns B-L

Private Sub cmdNewRoom_Click()
Sheets("materials2").Select
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("materials2")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 4) _
.End(xlUp).Offset(1, 0).Row
ws.Cells(iRow, 2).Value = Me.txtRoomName.Value
.Interior.Color = RGB(83, 142, 213)
End Sub

Bob Phillips
09-03-2012, 01:37 PM
Private Sub cmdNewRoom_Click()
Sheets("materials2").Select
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("materials2")

With ws

'find first empty row in database
iRow = .Cells(.Rows.Count, 4).End(xlUp).Offset(1, 0).Row
.Cells(iRow, 2).Value = Me.txtRoomName.Value
.Interior.Color = RGB(83, 142, 213)
End With
End Sub