Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Help with a VBS Problem, please?

 
Logged in as: Guest
arrSession:exec spGetSession 2,7,60158
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [General Forum] >> Other Programming/Scripting Languages >> Help with a VBS Problem, please?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Help with a VBS Problem, please? - 5/13/2008 5:13:42 AM   
  alcornj

 

Posts: 4
Score: 0
Joined: 5/13/2008
Status: offline
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 -- 5/13/2008 5:16:05 AM >
 
 
Post #: 1
 
 RE: Help with a VBS Problem, please? - 5/16/2008 2:31:36 AM   
  alcornj

 

Posts: 4
Score: 0
Joined: 5/13/2008
Status: offline
Dear god, anybody? Please?  Help?

(in reply to alcornj)
 
 
Post #: 2
 
 RE: Help with a VBS Problem, please? - 5/16/2008 10:36:44 AM   
  TNO


Posts: 1064
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
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

(in reply to alcornj)
 
 
Post #: 3
 
 RE: Help with a VBS Problem, please? - 5/17/2008 12:26:15 AM   
  alcornj

 

Posts: 4
Score: 0
Joined: 5/13/2008
Status: offline
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.

(in reply to TNO)
 
 
Post #: 4
 
 RE: Help with a VBS Problem, please? - 5/19/2008 6:57:07 AM   
  alcornj

 

Posts: 4
Score: 0
Joined: 5/13/2008
Status: offline
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.

(in reply to alcornj)
 
 
Post #: 5
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [General Forum] >> Other Programming/Scripting Languages >> Help with a VBS Problem, please? Page: [1]
Jump to:





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
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts