Sub MyAddNumbers()
Dim maxCol As Long
Dim maxRow As Long
Dim r As Long
Dim cs As Long
Dim ce As Long
Application.ScreenUpdating = False
' Set maximum number of rows and columns to search
maxCol = 100
maxRow = 100
' Loop through all rows
For r = 1 To maxRow
' Find first colored column in row
For cs = 1 To maxCol
If Cells(r, cs).Interior.Color <> 16777215 Then
Cells(r, cs) = 1
Exit For
End If
Next cs
' Find last colored column in row
For ce = maxCol To 1 Step -1
If Cells(r, ce).Interior.Color <> 16777215 Then
Cells(r, ce) = 2
Exit For
End If
Next ce
Next r
Application.ScreenUpdating = True
MsgBox "Macro complete"
End Sub