Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Visual basic help

  • 29-11-2008 10:10PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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
Advertisement