View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Apply format to 0 cells

Firstly note that a space and underscore at the end of a line is a line break
in an otherwise single line of code.

I have had to guess a little to correct some of your code. The following
line does not say which sheet Range("A3") belongs to.

If Sheets("Sheet2").Cells(R, 1).Value = Range("A3") Then

I changed it to the following. Edit to the correct sheet if required.

If Sheets("Sheet2").Cells(R, 1).Value _
= Sheets("Sheet2").Range("A3") Then

I had difficulty working out what range you wanted in the following line.

Set rngTemp = Sheets("Sheet2").Cells(R, 1).Range("C1:S1")

I changed it to the following.

With Sheets("Sheet2")
Set rngTemp = .Range(.Cells(R, 1), .Cells(R, "S"))
End With

Revamped code as follows but I am really not sure that my assumptions above
are correct for what you want so feel free to get back to me.

Sub Decorate()
Dim rngB As Range
Dim rngTemp As Range
Dim c As Range
Dim R As Long

Set rngB = Sheets("Sheet2").UsedRange.Columns("A:S")
For R = 1 To rngB.Rows.Count
If Sheets("Sheet2").Cells(R, 1).Value _
= Sheets("Sheet2").Range("A3") Then

With Sheets("Sheet2")
Set rngTemp = .Range(.Cells(R, 1), .Cells(R, "S"))
End With

For Each c In rngTemp
If c.Value < 1 Then
c.Font.Bold = True
With c.Interior
.ColorIndex = 41
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
Next c
End If
Next R
End Sub

--
Regards,

OssieMac


"BeSmart" wrote:

Hi All
I have a code below that formats cells - but it formats all cells in the row
& I need it to only format cells 0 in the row.
I tried a few things and got errors .... How do I incorporate the additional
If Then Else into this code?

Sub Decorate()
Dim rngB As Range
Dim rngTemp As Range
Set rngB = Sheets("Sheet2").UsedRange.Columns("A:S")
For R = 1 To rngB.Rows.Count
If Sheets("Sheet2").Cells(R, 1).Value = Range("A3") Then
Set rngTemp = Sheets("Sheet2").Cells(R, 1).Range("C1:S1")

'''' If rngTemp.Value <1 Then (I tried adding this - but got a "type
mismatch" error???)
''' Else

rngTemp.Font.Bold = True
With rngTemp.Interior
.ColorIndex = 41
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
'''' End If
End If
Next R
End Sub
--
Thank for your help
BeSmart