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>