Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Visual basic help

Options
  • 29-11-2008 10:10pm
    #1
    Registered Users Posts: 929 ✭✭✭


    Im very new to this language, only starting to learn it in the last few weeks.
    I have 1 problem with a piece of code I have written.

    The range from D2 onwards contain numerical values. When it runs and prints out the sumtotal is clears D2 and does not include it in the sumtotal. I cant understand why this is... Any help would be greatly appreciated :)

        Sheets("a").Select
        Range("D2").Select
        ActiveCell.Value = sumtotal
        
        Do While ActiveCell.Value <> ""
        sumtotal = sumtotal + ActiveCell.Value
        ActiveCell.Offset(1, 0).Select
        Loop
        
        Sheets("Inventory").Select
        Range("B5") = sumtotal
    


Comments

  • Closed Accounts Posts: 3,357 ✭✭✭Beano


    sternn wrote: »
    Im very new to this language, only starting to learn it in the last few weeks.
    I have 1 problem with a piece of code I have written.

    The range from D2 onwards contain numerical values. When it runs and prints out the sumtotal is clears D2 and does not include it in the sumtotal. I cant understand why this is... Any help would be greatly appreciated :)

        Sheets("a").Select
        Range("D2").Select
        [B]ActiveCell.Value = sumtotal[/B]
        
        Do While ActiveCell.Value <> ""
        sumtotal = sumtotal + ActiveCell.Value
        ActiveCell.Offset(1, 0).Select
        Loop
        
        Sheets("Inventory").Select
        Range("B5") = sumtotal
    

    the line in bold is the problem. you are putting the value of the sumtotal variable into cell D2. as that variable doesnt have a value at that point the cell is blanked. what is the purpose of having that line in there?


  • Registered Users Posts: 929 ✭✭✭sternn


    I was thinking it would add to sumtotal before it moved on, but thinking of it logically now it makes sense. Thanks!


  • Closed Accounts Posts: 3,357 ✭✭✭Beano


    sternn wrote: »
    I was thinking it would add to sumtotal before it moved on, but thinking of it logically now it makes sense. Thanks!

    what you should do is set sumtotal = 0 at some point before the loop


Advertisement