Help with a VBS Problem, please?

Author Message
alcornj

  • Total Posts : 4
  • Scores: 0
  • Reward points : 0
  • Joined: 5/13/2008
  • Status: offline
Help with a VBS Problem, please? Tuesday, May 13, 2008 6:13 AM (permalink)
0
Hello all, my name is Josh and I'm a java/c++ programmer and know literally nothing about vb/vbs and decided to try my luck at writing a custom script for a work-related excel sheet. Brevity isn't quite my thing but I promise I'll try my best when I explain:

I've got a spreadsheet set up to keep track of data, in this case whenever an employee comes in late I type the date into a cell. At the bottom of the list is a box that keeps a running total of how many boxes I've filled. Im facing two problems with it and I have literally no idea what to do, and I can't seem to find anything for vb that works similar to javadoc insofar as explaining vb functions, etc. Heres the problem. If I type data into consecutive cells, my script works just fine. The table is set up so cells c11 through c44 are looked at for dates. If I start at c11 and don't skip any cells then thats fine. However if I put data into c11, c12, and c14, for example, it will look at c11 and c12 and count 2 cells, but will ignore c14. What I want is to loop through each cell FROM c11 TO c44, and if its NOT empty update my count by 1, otherwise update it by 0. In theory if I were to put data into every odd cell, c11, c13, c15, c17, etc I want it to find and return 4 cells. Instead, its finding 1, in c11, and ignoring everything else.

Next, there are four "sets" of data I want to track. Colum C counts lates, Column D counts absences, and I use E and F as well. I need to do this four times on my page, one for each set. All colums use rows 11 through 44. Can anybody tell me how to get it to work how I want? I don't even know excel enough to know if theres some other way to do it and I don't know if I can use c/c++ or even java to write it instead? Thanks. Here is my code:


    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    Dim x As Integer
    Dim iCount As Integer
    iCount = 0
    ' Set numrows = number of rows of data.
    NumRows = Range("C11", Range("C44").End(xlUp)).Rows.Count
    'NumRows = Range("C11", Range("C44").End(xlDown)).Rows.Count
    ' Select cell C11.
    Range("C11").Select
    ' Establish "For" loop to loop "numrows" number of times.
    For x = 1 To NumRows
        If Not IsEmpty(ActiveCell) Then
            Application.EnableEvents = False
            iCount = iCount + 1
            Application.EnableEvents = True
            'Selects cell down 1 row from active cell.
            ActiveCell.Offset(1, 0).Select
'              MsgBox "Cell" & ActiveCell.Address
        Else
            iCount = iCount + 0
'              MsgBox "Cell" & ActiveCell.Address
        End If
    Next
             Range("C46").Value = iCount
End Sub
<message edited by alcornj on Tuesday, May 13, 2008 6:16 AM>
 
#1
    alcornj

    • Total Posts : 4
    • Scores: 0
    • Reward points : 0
    • Joined: 5/13/2008
    • Status: offline
    RE: Help with a VBS Problem, please? Friday, May 16, 2008 3:31 AM (permalink)
    0
    Dear god, anybody? Please?  Help?
     
    #2
      TNO

      • Total Posts : 2094
      • Scores: 36
      • Reward points : 0
      • Joined: 12/18/2004
      • Location: Earth
      • Status: offline
      RE: Help with a VBS Problem, please? Friday, May 16, 2008 11:36 AM (permalink)
      0
      I don't think VBA is needed for this case, the spreadsheet formulas should be plenty. Go to insert formula and look at the COUNT and COUNTIF functions. play with them a little and some others and you can get on the right track pretty fast. VBA is overkill in many instances IMO (I'm not counting Macros, that's a different story). If confused, the insert formula dialog lets you type in a description or a question to find something you need.
      To iterate is human, to recurse divine. -- L. Peter Deutsch
       
      #3
        alcornj

        • Total Posts : 4
        • Scores: 0
        • Reward points : 0
        • Joined: 5/13/2008
        • Status: offline
        RE: Help with a VBS Problem, please? Saturday, May 17, 2008 1:26 AM (permalink)
        0
        I'll have to look into it... I have no idea what you're talking about. :P Thanks a ton for the advice, it shouldn't be too hard to research. I really really appreciate your reply. Thank you.
         
         
        #4
          alcornj

          • Total Posts : 4
          • Scores: 0
          • Reward points : 0
          • Joined: 5/13/2008
          • Status: offline
          RE: Help with a VBS Problem, please? Monday, May 19, 2008 7:57 AM (permalink)
          0
          That was way way way simpler then what I was trying to do and worked better then I could have coded it myself. Thanks a ton for the advice. I wound up using counta and it was perfect. Thanks again.
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9