Thread: Range error
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default Range error

Not quite sure what you are trying to end up with but
Range1=range("D" & row &":"G" & row)
or
range1=range(cells(row,"d"),cells(row,"G"))

======
Private Sub CommandButton2_Click()
Dim row As Integer
row = 4
Dim Range1 As Range

Range1=("D" & row &":"G" & row) ' THIS LINE HAS THE ERROR MESSAGE

For Each a In Range1
If a.Value = "N/A" Then
a.Font.ColorIndex = 1
ElseIf a.Value = 0.945 Then
a.Font.ColorIndex = 10
ElseIf a.Value 0.895 Then
a.Font.ColorIndex = 44
ElseIf a.Value = 0 Then
a.Font.Color = vbRed
Else
a.Font.Color = vbBlack
End If
row.Value = row.Value + 4
Next
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"aimee209" wrote in message
...
When I type in the code, I get an error when I try to define the range

Private Sub CommandButton2_Click()
Dim row As Integer
row = 4
Dim Range1 As Range

Range1=("D" & row:"G" & row) ' THIS LINE HAS THE ERROR MESSAGE

For Each a In Range1
If a.Value = "N/A" Then
a.Font.ColorIndex = 1
ElseIf a.Value = 0.945 Then
a.Font.ColorIndex = 10
ElseIf a.Value 0.895 Then
a.Font.ColorIndex = 44
ElseIf a.Value = 0 Then
a.Font.Color = vbRed
Else
a.Font.Color = vbBlack
End If
row.Value = row.Value + 4
Next
End Sub

Thanks!