Results 1 to 10 of 10

Thread: Need help! Excel & VBA trouble

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Exclamation Need help! Excel & VBA trouble

    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:
    1. Sub chk()
    2. Dim iCompare As Long
    3. Dim iCheck As Long
    4. Dim XL As Variant
    5. Dim xlWS As Variant
    6. Dim Checksum As Variant
    7. Dim Compare As Variant
    8. Dim Value_chk As Integer
    9. Dim Kolonne As Variant
    10.  
    11. Set xlWS = Sheet3
    12.  
    13. iCompare = 3
    14. iCheck = 2
    15. Value_chk = 3
    16. Kolonne = 7
    17.  
    18. Columns(Value_chk).Interior.Color = RGB(255, 255, 255)
    19.  
    20. Do While xlWS.Cells(iCheck, Value_chk).Value <> ""
    21.     Do While xlWS.Cells(iCompare, Value_chk).Value <> ""
    22.         Checksum = Cells(iCheck, Kolonne).Value
    23.         Compare = Cells(iCompare, Kolonne).Value
    24.         If Checksum = Compare Then
    25.             GoTo Hvid
    26.             GoTo Ring
    27.             End If
    28. Hvad:
    29.             If Checksum <> Compare Then
    30.             GoTo Her
    31.             Else: GoTo Hvid
    32.             End If
    33.  
    34. Her:
    35.  
    36.             If Kolonne <= 19 Then
    37.             With Cells(iCheck, 3).Interior
    38.             .Color = RGB(255, 0, 0)
    39.             End With
    40.             With Cells(iCompare, 3).Interior
    41.             .Color = RGB(255, 0, 0)
    42.             End With
    43.            
    44.            Else
    45.            GoTo Ring
    46.            End If
    47.            
    48.            
    49. Hvid:
    50.            
    51.            iCompare = iCompare + 1
    52.            
    53. Ring:
    54.          Loop
    55.          
    56. iCompare = iCheck + 2
    57. iCheck = iCheck + 1
    58.  
    59. Loop
    60. With Columns(Value_chk).Borders(xlEdgeLeft)
    61.         .LineStyle = xlContinuous
    62.         .Weight = xlThin
    63.         .ColorIndex = xlAutomatic
    64.     End With
    65.     With Columns(Value_chk).Borders(xlEdgeTop)
    66.         .LineStyle = xlContinuous
    67.         .Weight = xlThin
    68.         .ColorIndex = xlAutomatic
    69.     End With
    70.     With Columns(Value_chk).Borders(xlEdgeBottom)
    71.         .LineStyle = xlContinuous
    72.         .Weight = xlThin
    73.         .ColorIndex = xlAutomatic
    74.     End With
    75.     With Columns(Value_chk).Borders(xlEdgeRight)
    76.         .LineStyle = xlContinuous
    77.         .Weight = xlThin
    78.         .ColorIndex = xlAutomatic
    79.     End With
    80.     With Columns(Value_chk).Borders(xlInsideHorizontal)
    81.         .LineStyle = xlContinuous
    82.         .Weight = xlThin
    83.         .ColorIndex = xlAutomatic
    84.     End With
    85.      
    86. End Sub

    Hope you understand me



    Edit: Fixed [/vbcode] end tag. - Hack
    Last edited by Hack; Sep 8th, 2005 at 10:16 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width