Results 1 to 3 of 3

Thread: Excel Programming Problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    12

    Excel Programming Problem

    hi,

    I´ve got a problem:
    I programmed this sub:


    Public Sub FalscherVorgang()

    ArrayVorgangDefinieren
    ArrayBausteinDefinieren
    (these are the arrays i need to use further down)


    Workbooks.Open("S:\SEKRETAR\Allgemein\Vorlagen\umwandlung zeiterf. öst-brd.xls")

    For x = 5 To 981
    Vorgangvorgabe(x) = Workbooks(3).Worksheets("Umrechentabelle").Cells(x, 1)
    Next x

    For y = 5 To 981
    Bausteinvorgabe(y) = Workbooks(3).Worksheets("Umrechentabelle").Cells(y, 2)
    Next y


    for w = 5 To 981
    If (Vorgang(0) = Vorgangvorgabe(w)) Then
    Else
    If (Vorgang(1) = Vorgangvorgabe(w)) Then
    Else

    and so on......

    Else
    MsgBox ("There is a mistake")

    Next w


    the problem is that it always displays the message box.....
    even if i put a valid number in the Vorgang(0)-field and display a message-box if the values match, the mistake-msgbox is displayed.

    can anybody help me?

    thx, alex

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

    Re: Excel Programming Problem

    Originally posted by alexschiefert
    VB Code:
    1. Public Sub FalscherVorgang()
    2.  
    3. ArrayVorgangDefinieren
    4. ArrayBausteinDefinieren
    5.  
    6.  
    7. Workbooks.Open("S:\SEKRETAR\Allgemein\Vorlagen\umwandlung zeiterf. öst-brd.xls")
    8.  
    9. For x = 5 To 981
    10. Vorgangvorgabe(x) = Workbooks(3).Worksheets("Umrechentabelle").Cells(x, 1)
    11. Next x
    12.  
    13. For y = 5 To 981
    14. Bausteinvorgabe(y) = Workbooks(3).Worksheets("Umrechentabelle").Cells(y, 2)
    15. Next y
    16.  
    17.  
    18. [B]for w = 5 To 981[/B]
    19. [B]If (Vorgang(0) = Vorgangvorgabe(w)) Then
    20. Else
    21. If (Vorgang(1) = Vorgangvorgabe(w)) Then
    22. Else
    23.  
    24. 'and so on......
    25.  
    26. Else
    27. MsgBox ("There is a mistake")
    28.  
    29. Next
    Ok, so you are opening a sheet, putting two loadss of values in from said sheet, starting at row 5. This means 0-4 are empty.

    Also you want to use a boolean (really you do) variable as aflag if its valid or not, then make a loop to check for you setting to false if its not valid... something like the following...
    VB Code:
    1. blnValid = true
    2.     For lngX = 0 to 1000
    3.         if not (aryOne(lngx)=aryTwo(lngx) then blnValid = false
    4.     Next
    5.  
    6.     if blnValid then
    7.           msgbox "fine"
    8.     else
    9.          msgbox "mistake"
    10.     end if

    Cuts your code down a bit too.

    Vorgang array I assume is already set up??
    When storing, if you put into the arrays using x-5 as a position you can do the loop I made above.

    Possibly the error is a conversion error, in that the two values in the arrays don't match.

    Post up if you get it working, or if you use this loop. Or if it still don't work

    Vince

    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...

  3. #3
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    VB Code:
    1. for w = 5 To 981
    2. If (Vorgang(0) = Vorgangvorgabe(w)) Then
    3. Else
    4. If (Vorgang(1) = Vorgangvorgabe(w)) Then
    5. Else
    6.  
    7. and so on......
    8.  
    9. Else
    10. MsgBox ("There is a mistake")
    11.  
    12. Next w
    Your Else / If statement could be wrong.

    I think this:
    VB Code:
    1. If Condition Then
    2.   Statement
    3. Else
    4. If Condition Then
    5.   Statement
    6. Else
    7.   Statement
    8. End If

    Is different from this:
    VB Code:
    1. If Condition Then Statement
    2. ElseIf Condition Then
    3.   Statement
    4. ElseIf Condition Then
    5.   Statement
    6. Else
    7.   Statement
    8. End If

    Try the latter.

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