Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a program, that with a lot of help here, works ok. The problem
is, that as I test it on addtional spreadsheets that it has to run on, I'm finding more codes that I hadn't accounted for. I originally wrote the program to eliminate non-counted codes. I realize now that I should have originally written the code to only include the codes I want to count, and just skip the others. This would also remove the need for some of the other qualifiers, like "?" and other things that appear in some of the sheets, that aren't counted. Here's the code as is (all variables declared): Const PWORD As String = "2005totals" lEndRow = 1000 lTotNameRow = 4 Set wksSrc = ActiveSheet Set wksTot = ActiveWorkbook.Sheets("TOTALS") Set rngCode = wksSrc.Range("D8:D" & lEndRow) wksTot.Unprotect Password:=PWORD strMonWksht = wksSrc.Name & " - Monthly" Set wksMon = Sheets(strMonWksht) wksMon.Range("B4:K15").ClearContents For Each rngCell In rngCode dteColCode = 0 If rngCell < "na" Then If rngCell < "?" Then If Len(rngCell) < 3 Then If rngCell < 0 Then If rngCell < 10 Then If rngCell < 11 Then If rngCell < 15 Then If rngCell < "" Then 'Counting the codes needed happens here End If End If End If End If End If End If End If Next rngCell End Sub If I change the series of tests to something like If rngCell = 14 then 'do the counting else if rngCell = 7 'do the counting else Etc, etc. I have a bunch of If statements that if true, go to the counting routine. But I don't want to repeat the same code over and over. If I call a routine to do the counting, when it returns, I want it to go to the next cell in rngCode, not the next test, which is now unneccessary. If rngCell is not equal to any of the tested values, I want it to go to Next rngCell in rngCode. I'm not sure how to code all this without, heaven forbid, branching! Is it considered "branching" if the program goes to the counting routine, and the counting routine sends it back to the beginning of the testing routine, rather than back to the same place in the code it was called from? It seems it would be very easy to end up in an endless loop this way, although if I did it right, it wouldn't really happen. But I think that part of the reason branching is "heresy" is because of the possibility of endless looping. Can someone show me how this is done? Thanks! |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Bug or wrong approach | Excel Worksheet Functions | |||
What is the right approach? | Excel Worksheet Functions | |||
How to approach this? | Excel Discussion (Misc queries) | |||
How do I approach this little Project, please? | Excel Programming | |||
How do I approach this? | Excel Programming |