Hi there.
I need VBA to compare several cells in Excel. It's rather difficault to explain the situation, but I'll try it.
Here's is the spreadsheet (| | represent a single cell):
| 0466-1-1-1-1 | 01 | - | 01 | - | 01 | - | 01 |
| 0466-1-1+1 | 01 | - | 01 | + | 01 |
| 0466-1-1 | 01 | - | 01 |
The first one is correct, the other 2 are wrong, while e.g.
| 0466-1-3+1 | 01 | - | 03 | + | 01 |
is correct.
Here's my code:
VB Code:
Sub chk() Dim iCompare As Long Dim iCheck As Long Dim XL As Variant Dim xlWS As Variant Dim Checksum As Variant Dim Compare As Variant Dim Value_chk As Integer Dim Kolonne As Variant Set xlWS = Sheet3 iCompare = 3 iCheck = 2 Value_chk = 3 Kolonne = 7 Columns(Value_chk).Interior.Color = RGB(255, 255, 255) Do While xlWS.Cells(iCheck, Value_chk).Value <> "" Do While xlWS.Cells(iCompare, Value_chk).Value <> "" Checksum = Cells(iCheck, Kolonne).Value Compare = Cells(iCompare, Kolonne).Value If Checksum = Compare Then GoTo Hvid GoTo Ring End If Hvad: If Checksum <> Compare Then GoTo Her Else: GoTo Hvid End If Her: If Kolonne <= 19 Then With Cells(iCheck, 3).Interior .Color = RGB(255, 0, 0) End With With Cells(iCompare, 3).Interior .Color = RGB(255, 0, 0) End With Else GoTo Ring End If Hvid: iCompare = iCompare + 1 Ring: Loop iCompare = iCheck + 2 iCheck = iCheck + 1 Loop With Columns(Value_chk).Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Columns(Value_chk).Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Columns(Value_chk).Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Columns(Value_chk).Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Columns(Value_chk).Borders(xlInsideHorizontal) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With End Sub
Hope you understand me
Edit: Fixed [/vbcode] end tag. - Hack





Reply With Quote