Results 1 to 3 of 3

Where is this 'count responses' code failing?

Threaded View

  1. #1
    Registered User
    Join Date
    07-24-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    73

    Where is this 'count responses' code failing?

    Hello,

    As you can see below, I have used 15 variables to store the counts for different combinations in response to the question "Have you ever been a member of the armed forces?"

    My output table is the problem because it groups responses by gender, separating men who have served in the forces, from women who have served etc.

    It outputs the final counts into a table, HOWEVER.

    Any response other than male fails to work and the output is always 0.

    Can anybody help correct the below code?



    Sub Forces()
    
    Dim Ws As Worksheet
    
    Dim maleyes As Long
    Dim malevet As Long
    Dim maleno As Long
    Dim femaleyes As Long
    Dim femalevet As Long
    Dim femaleno As Long
    Dim intersexyes As Long
    Dim intersexvet As Long
    Dim intersexno As Long
    Dim otheryes As Long
    Dim othervet As Long
    Dim otherno As Long
    Dim prefyes As Long
    Dim prefvet As Long
    Dim prefno As Long
    
    For Each Ws In ActiveWorkbook.Worksheets
    
    If Ws.Range("F6") = "Male" Then
    If Ws.Range("H10") = "Yes - Serving" Then
    maleyes = maleyes + 1
    ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("H10") = "Yes - Veteran" Then
    malevet = malevet + 1
    ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("H10") = "No - not and never been a member" Then
    maleno = maleno + 1
    ElseIf Ws.Range("F6") = "Female" Then
    If Ws.Range("H10") = "Yes - Serving" Then
    femaleyes = femaleyes + 1
    ElseIf Ws.Range("F6") = "Female" Then
    If Ws.Range("H10") = "Yes - Veteran" Then
    femalevet = femalevet + 1
    ElseIf Ws.Range("F6") = "Female" Then
    If Ws.Range("H10") = "No - not and never been a member" Then
    femaleno = femaleno + 1
    ElseIf Ws.Range("F6") = "Intersex" Then
    If Ws.Range("H10") = "Yes - Serving" Then
    intersexyes = intersexyes + 1
    ElseIf Ws.Range("F6") = "Intersex" Then
    If Ws.Range("H10") = "Yes - Veteran" Then
    intersexvet = intersexvet + 1
    ElseIf Ws.Range("F6") = "Intersex" Then
    If Ws.Range("H10") = "No - not and never been a member" Then
    intersexno = intersexno + 1
    ElseIf Ws.Range("F6") = "Other" Then
    If Ws.Range("H10") = "Yes - Serving" Then
    otheryes = otheryes + 1
    ElseIf Ws.Range("F6") = "Other" Then
    If Ws.Range("H10") = "Yes - Veteran" Then
    othervet = othervet + 1
    ElseIf Ws.Range("F6") = "Other" Then
    If Ws.Range("H10") = "No - not and never been a member" Then
    otherno = otherno + 1
    ElseIf Ws.Range("F6") = "Prefer not to say" Then
    If Ws.Range("H10") = "Yes - Serving" Then
    prefyes = prefyes + 1
    ElseIf Ws.Range("F6") = "Prefer not to say" Then
    If Ws.Range("H10") = "Yes - Veteran" Then
    prefvet = prefvet + 1
    ElseIf Ws.Range("F6") = "Prefer not to say" Then
    If Ws.Range("H10") = "No - not and never been a member" Then
    prefno = prefno + 1
    
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    
    Next Ws
    
    Cells(76, 2).Value = maleyes
    Cells(76, 3).Value = malevet
    Cells(76, 4).Value = maleno
    Cells(77, 2).Value = femaleyes
    Cells(77, 3).Value = femalevet
    Cells(77, 4).Value = femaleno
    Cells(78, 2).Value = intersexyes
    Cells(78, 3).Value = intersexvet
    Cells(78, 4).Value = intersexno
    Cells(79, 2).Value = otheryes
    Cells(79, 3).Value = othervet
    Cells(79, 4).Value = otherno
    Cells(80, 2).Value = prefyes
    Cells(80, 3).Value = prefvet
    Cells(80, 4).Value = prefno
    
    
    End Sub
    Linked Post: http://www.mrexcel.com/forum/excel-q...ml#post3814373
    Last edited by henryBukowski; 05-21-2014 at 06:19 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] potential indirect countif: trying to count unique values giving same responses
    By j.farr3ll in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-14-2013, 08:00 AM
  2. Replies: 3
    Last Post: 10-28-2012, 09:22 PM
  3. Replies: 3
    Last Post: 04-26-2011, 05:12 PM
  4. Code failing after x = 281
    By sach_83 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2011, 04:33 PM
  5. Count responses across multiple worksheets
    By dwalzak in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-30-2010, 09:38 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1