Results 1 to 10 of 10

Thread: Need help! Excel & VBA trouble

  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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Need help! Excel & VBA trouble

    Moved to Office Development

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need help! Excel & VBA trouble

    A couple of things,
    Dont use GoTos they are not very good to use and makes your code hard to read.
    What is it that your trying to compare? Are you just looking for blank cells?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Re: Need help! Excel & VBA trouble

    I can't use anything else.
    It's hard to explain. Any numbers that are shorter and contain the same numbers than e.g. 0466-1-1-1-1-1+1 are wrong, while a number such as 0466-1-3 is correct. Every number is seperated into their own cells.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need help! Excel & VBA trouble

    So this is one row...
    Code:
      A  | B | C | D | E | F | G
    ---------------------------
    0466 | 1 | 1 | 1 | 1 | 1 | 1
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Re: Need help! Excel & VBA trouble

    Exactly - well, almost...there is a "-" between all numbers, except for the last two - there's a "+" that seperates them

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need help! Excel & VBA trouble

    Ok, but can you explain why they are wrong? It will make it easier to try to come up with some code for.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Need help! Excel & VBA trouble

    uh not sure what you mean .... but try:
    Code:
    =concatenate("0466-",<cellref>,<cellref>,<cellref>)
    Or do you mean that your code has to split the first complete one, remove all the first digits to the '-' then shove all other elements (numbers and -/+ signs) into separate cells?

    (if so then your first example you have said that the second two lines of is wrong, it isn't)


    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Re: Need help! Excel & VBA trouble

    I was right that it was hard to explain This is the situation:

    | A | B | C | D | E | F | G | H | I | J | K | L | M
    ---------------------------
    0466 | - | 1 | - | 1 | - | 1 | - | 1 | - | 1 | + | 1
    0466 | - | 1 | - | 1 |
    0466 | - | 1 | | | | | | | | | + | 1
    0466 | - | 1 | - | 3 |

    Now, row no 1 is correct.
    Row no 2 has the same numbers, but is too short - therefore it's wrong.
    Same with row no 3, although it has a '+' instead af a '-'.
    Row no 4 is correct, because at least one of it's numbers is different from the other rows

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Re: Need help! Excel & VBA trouble

    Is it confusing, or is the solution complicated? :S

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