Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 21

Thread: Testing multipe counters

  1. #1
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    Testing multipe counters

    How can you test multiple counters for a value of 1 or more programatically?
    Peace of mind is found in some of the strangest places.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by austenr
    How can you test multiple counters for a value of 1 or more programatically?
    How do you define multiple counters.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Here is the whole routine. It is really ugly and probably does not produce the desired result (at least I can't get it to work). It is totally my work and really ugly. What it is supposed to do is, check row by row, and depending on if the value in column G has changed or not add to counters and do other things. Could someone please look it over. Thanks.



    Option Explicit
     
    Public Sub DetermineSameSocial()
    ' Checks to see if the value in column G is the same as the previous row
    ' If not Add to coverage types and clear temporary counters
    ' Else process row
    Dim s, Row, LastRow, SELF, ECH, FAM, ESP, tempss, tempself, tempch, _
    tempfam, tempesp, tempsp, tempech As Integer
    Range("G:I").Select
    Row = 2
    For s = 1 To LastRow
    Range("G").Value = tempss
    If Range("G").Value > tempss Then
    DetermineCov
    ClearTmpCntrs
    End If
    ' Add to counters
    If Range("I").Value = "SELF" Then
    tempself = tempself + 1
    Else
    If Range("I").Value = "CHILD" Then
    tempch = tempch + 1
    Else
    If Range("I").Value = "SPOUSE" Then
    tempsp = tempsp + 1
    End If
    End If
    End If
    Next s
    MsgBox ("Self" + tempself)
    End Sub
     
    Public Sub DetermineCov()
    Dim tempself, tempch, tempsp, tempfam, tempesp, tempech As Integer
    ' Determine self coverage
    If tempself >= 1 And tempch = 0 And tempsp = 0 Then
    tempself = 1
    End If
    'Determine Family Coverage
    If tempself >= 1 And tempch >= 1 And tempsp >= 1 Then
    tempfam = 1
    End If
    'Determine Employee Plus Spouse coverage
    If tempself >= 1 And tempsp >= 1 And tempch = 0 Then
    tempesp = 1
    End If
    'Determine Employee plus child Coverage
    If tempself >= 1 And tempch >= 1 And tempsp = 0 Then
    tempech = 1
    End If
    End Sub
     
    Public Sub ClearTmpCntrs()
    Dim tempself, tempch, tempsp As Integer
    tempself = 0
    tempch = 0
    tempsp = 0
    End Sub
    Peace of mind is found in some of the strangest places.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post some spreadsheet data to test on?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    here
    Peace of mind is found in some of the strangest places.

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    One way of doing this (not having seen your data) is the same as the inputbox method for buttons. You use a single variable and add a figure of 2^n for each option. You can then analyse this using a select case statement, for any combination of data. Whether this is practicable, depends upon your number of variables of course.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    totally confused... Example please

    Peace of mind is found in some of the strangest places.

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Sorry Austen,
    I hadn't seen you data when I posted that solution.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    so i canot do it that way?
    Peace of mind is found in some of the strangest places.

  10. #10
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    What is tempss?
    Range("G").Value = tempss
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  11. #11
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    I need a way to compare the value in G(row# which in the example file is column A) when I go to the next row. If it is not the same, then I need to do the decide coverage routine and clear the temp totals. HTH
    Peace of mind is found in some of the strangest places.

  12. #12
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Austen,
    Have a look at the attached. Its a different methodology, and there are other ways to approch this. It's not 100% as you will see, but maybe you can iron out the bugs.
    I've got to go and cut the grass!

    Corrected file now attached.
    Last edited by mdmackillop; 05-10-2005 at 12:46 PM. Reason: Corrected file attached
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  13. #13
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Thanks. That works like you said. Can't figure out how it gets off track and then back on!! Your work is appreciated. I am attaching the file and is highlighted where it gets off track. If anyone else wants to take a crack at it.
    Peace of mind is found in some of the strangest places.

  14. #14
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    revised file
    Peace of mind is found in some of the strangest places.

  15. #15
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Grass cut!
    I hadn't reset TempMem.

    If .Value <> Tempss Then
    TempFam = 0
    TempMem = ""
    End If
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  16. #16
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Austen,

    I've tidied up and attached my corrected file to Post 12 above.
    Please note that this code will not give the correct answer in Child values in a group are split, eg by Spouse or Self. If this is a possibility, let me know.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  17. #17
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Not sure what you mean..
    Peace of mind is found in some of the strangest places.

  18. #18
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    In column I, Self, Child, Spouse, Child in one Family would give a different result from
    Self, Spouse, Child, Child, because the code triggers on a Column I change (as well as column G) It depends upon your data entry etc. whether this might occur and be a problem.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  19. #19
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    If I sorted both columns with the primary being G and secondary I would that work?
    Peace of mind is found in some of the strangest places.

  20. #20
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Yes, that would do it.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •