after seeing your sample workbook heres the modded code, but please delete any empty lines on the worksheet.

Sub ChangeCellColor()



Dim str1, str2 As String
Dim lastrow As Integer
Dim lastcol As Integer

str1 = "AB1"
str2 = "AB2"


Columns(1).Font.Color = vbBlack

lastrow = Cells(1, 4).End(xlDown).Row



For i = 1 To lastrow

'If the current cell in the D column contains either the string AB1 or AB2, it will look into the values here.
If Cells(i, 1).Value = str1 Or Cells(i, 1).Value = str2 Then
lastcol = Cells(i, 1).End(xlToRight).Column
For j = 2 To lastcol
If Cells(i, j).Value > 5 Then
Cells(i, j).Interior.ColorIndex = 4
ElseIf Cells(i, j).Value < 6 And Cells(i, j).Value > 3 Then
Cells(i, j).Interior.ColorIndex = 5
End If
Next j
End If
Next i

End Sub