Posted by: rajeshHamal May 19, 2009
Login in to Rate this Post:
0
?
option explicit
Sub sajha()
'vba for excel to
'determine if the adjacent cells have equal value
'declare variables
Dim myData As Range
Dim myRow As Range
Dim myCell As Range
Dim colCount As Long
Dim leftCell As Range
Dim rightCell As Range
'assign range
Set myData = Selection
'remove previous color
myData.Interior.ColorIndex = xlColorIndexNone
For Each myRow In myData.Rows
colCount = 0
For Each myCell In myRow.Cells
colCount = colCount + 1
'test for odd numbered columns in selection
If (colCount / 2 - colCount \ 2 <> 0) Then
Set leftCell = myCell
Set rightCell = myCell.Offset(0, 1)
If leftCell.Value = rightCell.Value Then
leftCell.Interior.Color = vbGreen
rightCell.Interior.Color = vbGreen
End If
End If
Next
Next
End Sub
Sub sajha()
'vba for excel to
'determine if the adjacent cells have equal value
'declare variables
Dim myData As Range
Dim myRow As Range
Dim myCell As Range
Dim colCount As Long
Dim leftCell As Range
Dim rightCell As Range
'assign range
Set myData = Selection
'remove previous color
myData.Interior.ColorIndex = xlColorIndexNone
For Each myRow In myData.Rows
colCount = 0
For Each myCell In myRow.Cells
colCount = colCount + 1
'test for odd numbered columns in selection
If (colCount / 2 - colCount \ 2 <> 0) Then
Set leftCell = myCell
Set rightCell = myCell.Offset(0, 1)
If leftCell.Value = rightCell.Value Then
leftCell.Interior.Color = vbGreen
rightCell.Interior.Color = vbGreen
End If
End If
Next
Next
End Sub