Failure outputting responses to cells

Henrybukowski

New Member
Joined
Apr 16, 2013
Messages
29
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?

Code:
[/COLOR][COLOR=#333333]Sub Forces()[/COLOR]

<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit;">Dim Ws As WorksheetDim maleyes As LongDim malevet As LongDim maleno As LongDim femaleyes As LongDim femalevet As LongDim femaleno As LongDim intersexyes As LongDim intersexvet As LongDim intersexno As LongDim otheryes As LongDim othervet As LongDim otherno As LongDim prefyes As LongDim prefvet As LongDim prefno As LongFor Each Ws In ActiveWorkbook.WorksheetsIf Ws.Range("F6") = "Male" ThenIf Ws.Range("H10") = "Yes - Serving" Thenmaleyes = maleyes + 1ElseIf Ws.Range("F6") = "Male" ThenIf Ws.Range("H10") = "Yes - Veteran" Thenmalevet = malevet + 1ElseIf Ws.Range("F6") = "Male" ThenIf Ws.Range("H10") = "No - not and never been a member" Thenmaleno = maleno + 1ElseIf Ws.Range("F6") = "Female" ThenIf Ws.Range("H10") = "Yes - Serving" Thenfemaleyes = femaleyes + 1ElseIf Ws.Range("F6") = "Female" ThenIf Ws.Range("H10") = "Yes - Veteran" Thenfemalevet = femalevet + 1ElseIf Ws.Range("F6") = "Female" ThenIf Ws.Range("H10") = "No - not and never been a member" Thenfemaleno = femaleno + 1ElseIf Ws.Range("F6") = "Intersex" ThenIf Ws.Range("H10") = "Yes - Serving" Thenintersexyes = intersexyes + 1ElseIf Ws.Range("F6") = "Intersex" ThenIf Ws.Range("H10") = "Yes - Veteran" Thenintersexvet = intersexvet + 1ElseIf Ws.Range("F6") = "Intersex" ThenIf Ws.Range("H10") = "No - not and never been a member" Thenintersexno = intersexno + 1ElseIf Ws.Range("F6") = "Other" ThenIf Ws.Range("H10") = "Yes - Serving" Thenotheryes = otheryes + 1ElseIf Ws.Range("F6") = "Other" ThenIf Ws.Range("H10") = "Yes - Veteran" Thenothervet = othervet + 1ElseIf Ws.Range("F6") = "Other" ThenIf Ws.Range("H10") = "No - not and never been a member" Thenotherno = otherno + 1ElseIf Ws.Range("F6") = "Prefer not to say" ThenIf Ws.Range("H10") = "Yes - Serving" Thenprefyes = prefyes + 1ElseIf Ws.Range("F6") = "Prefer not to say" ThenIf Ws.Range("H10") = "Yes - Veteran" Thenprefvet = prefvet + 1ElseIf Ws.Range("F6") = "Prefer not to say" ThenIf Ws.Range("H10") = "No - not and never been a member" Thenprefno = prefno + 1End IfEnd IfEnd IfEnd IfEnd IfEnd IfEnd IfEnd IfEnd IfEnd IfEnd IfEnd IfEnd IfEnd IfEnd IfEnd IfNext WsCells(76, 2).Value = maleyesCells(76, 3).Value = malevetCells(76, 4).Value = malenoCells(77, 2).Value = femaleyesCells(77, 3).Value = femalevetCells(77, 4).Value = femalenoCells(78, 2).Value = intersexyesCells(78, 3).Value = intersexvetCells(78, 4).Value = intersexnoCells(79, 2).Value = otheryesCells(79, 3).Value = othervetCells(79, 4).Value = othernoCells(80, 2).Value = prefyesCells(80, 3).Value = prefvetCells(80, 4).Value = prefno </code></pre>[COLOR=#333333]End Sub[/COLOR][COLOR=#333333]

Linked Post: Where is this 'count responses' code failing?
 
Your nestings are all wrong. Every If clause is subordinate to the first test for F6 being "Male" so no Female data will ever be processed. Your code is this once indented:
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

which will hopefully clarify the dependencies. I think what you want is this:
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("H10") = "Yes - Veteran" Then
            malevet = malevet + 1
        ElseIf Ws.Range("H10") = "No - not and never been a member" Then
            maleno = maleno + 1
        End If
    ElseIf Ws.Range("F6") = "Female" Then
        If Ws.Range("H10") = "Yes - Serving" Then
            femaleyes = femaleyes + 1
        ElseIf Ws.Range("H10") = "Yes - Veteran" Then
            femalevet = femalevet + 1
        ElseIf Ws.Range("H10") = "No - not and never been a member" Then
            femaleno = femaleno + 1
        End If
    
    ElseIf Ws.Range("F6") = "Intersex" Then
        If Ws.Range("H10") = "Yes - Serving" Then
            intersexyes = intersexyes + 1
        ElseIf Ws.Range("H10") = "Yes - Veteran" Then
            intersexvet = intersexvet + 1
        ElseIf Ws.Range("H10") = "No - not and never been a member" Then
            intersexno = intersexno + 1
        End If
    
    ElseIf Ws.Range("F6") = "Other" Then
        If Ws.Range("H10") = "Yes - Serving" Then
            otheryes = otheryes + 1
        ElseIf Ws.Range("H10") = "Yes - Veteran" Then
            othervet = othervet + 1
        ElseIf Ws.Range("H10") = "No - not and never been a member" Then
            otherno = otherno + 1
        End If
    ElseIf Ws.Range("F6") = "Prefer not to say" Then
        If Ws.Range("H10") = "Yes - Serving" Then
            prefyes = prefyes + 1
        ElseIf Ws.Range("H10") = "Yes - Veteran" Then
            prefvet = prefvet + 1
        ElseIf Ws.Range("H10") = "No - not and never been a member" Then
            prefno = prefno + 1
        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
 
Upvote 0
Aha!

You're a very intelligent man, you were spot on and the code now works a charm.

At first I could not identify whaty you'd done differently - but then I noticed the location of the 'End ifs'.

I actually have another, much bigger, piece of code with the same problem.

So what I need to do is end each If clause after the last 'ElseIf', and remove the 'End If' from the end.

I think this makes sense, and I've learnt something!

Thank you so very much Rory.
 
Upvote 0
Glad to help. If you are not restricted by work policies, I highly recommend installing Smart Indenter (ignore the fact it says Office 2000/2002/2003 - it works in all current versions too) which will allow you to indent your code with a simple click. It's very handy for spotting dependencies and missing 'End xxx' statements.
 
Upvote 0
Actually, I'm really sorry but need further advice!

I have code which is much longer and tries to combine three variables - gender, ethnicity, and age - resulting in hundreds of possible combinations: Can you just point me to where to put the 'End Ifs' with this one?

Code:
Sub thebigonea() 
Dim Ws As Worksheet




Dim Beetwelve As Long
Dim Beethirteen As Long
Dim Beefourteen As Long
Dim Beefifteen As Long
Dim Beesixteen As Long
Dim Beeseventeen As Long
Dim Beeeighteen As Long
Dim Beenineteen As Long
Dim Beetwenty As Long
Dim Ceetwelve As Long
Dim Ceethirteen As Long
Dim Ceefourteen As Long
Dim Ceefifteen As Long
Dim Ceesixteen As Long
Dim Ceeseventeen As Long
Dim Ceeeighteen As Long
Dim Ceenineteen As Long
Dim Ceetwenty As Long
Dim Deetwelve As Long
Dim Deethirteen As Long
Dim Deefourteen As Long
Dim Deefifteen As Long
Dim Deesixteen As Long
Dim Deeseventeen As Long
Dim Deeeighteen As Long
Dim Deenineteen As Long
Dim Deetwenty As Long
Dim Eeetwelve As Long
Dim Eeethirteen As Long
Dim Eeefourteen As Long
Dim Eeefifteen As Long
Dim Eeesixteen As Long
Dim Eeeseventeen As Long
Dim Eeeeighteen As Long
Dim Eeenineteen As Long
Dim Eeetwenty As Long
Dim Feetwelve As Long
Dim Feethirteen As Long
Dim Feefourteen As Long
Dim Feefifteen As Long
Dim Feesixteen As Long
Dim Feeseventeen As Long
Dim Feeeighteen As Long
Dim Feenineteen As Long
Dim Feetwenty As Long
Dim Geetwelve As Long
Dim Geethirteen As Long
Dim Geefourteen As Long
Dim Geefifteen As Long
Dim Geesixteen As Long
Dim Geeseventeen As Long
Dim Geeeighteen As Long
Dim Geenineteen As Long
Dim Geetwenty As Long
Dim Heetwelve As Long
Dim Heethirteen As Long
Dim Heefourteen As Long
Dim Heefifteen As Long
Dim Heesixteen As Long
Dim Heeseventeen As Long
Dim Heeeighteen As Long
Dim Heenineteen As Long
Dim Heetwenty As Long
Dim ieetwelve As Long
Dim ieethirteen As Long
Dim ieefourteen As Long
Dim ieefifteen As Long
Dim ieesixteen As Long
Dim ieeseventeen As Long
Dim ieeeighteen As Long
Dim ieenineteen As Long
Dim ieetwenty As Long
Dim Jeetwelve As Long
Dim Jeethirteen As Long
Dim Jeefourteen As Long
Dim Jeefifteen As Long
Dim Jeesixteen As Long
Dim Jeeseventeen As Long
Dim Jeeeighteen As Long
Dim Jeenineteen As Long
Dim Jeetwenty As Long
Dim Keetwelve As Long
Dim Keethirteen As Long
Dim Keefourteen As Long
Dim Keefifteen As Long
Dim Keesixteen As Long
Dim Keeseventeen As Long
Dim Keeeighteen As Long
Dim Keenineteen As Long
Dim Keetwenty As Long
Dim Leetwelve As Long
Dim Leethirteen As Long
Dim Leefourteen As Long
Dim Leefifteen As Long
Dim Leesixteen As Long
Dim Leeseventeen As Long
Dim Leeeighteen As Long
Dim Leenineteen As Long
Dim Leetwenty As Long
Dim Meetwelve As Long
Dim Meethirteen As Long
Dim Meefourteen As Long
Dim Meefifteen As Long
Dim Meesixteen As Long
Dim Meeseventeen As Long
Dim Meeeighteen As Long
Dim Meenineteen As Long
Dim Meetwenty As Long
Dim Neetwelve As Long
Dim Neethirteen As Long
Dim Neefourteen As Long
Dim Neefifteen As Long
Dim Neesixteen As Long
Dim Neeseventeen As Long
Dim Neeeighteen As Long
Dim Neenineteen As Long
Dim Neetwenty As Long
Dim Oeetwelve As Long
Dim Oeethirteen As Long
Dim Oeefourteen As Long
Dim Oeefifteen As Long
Dim Oeesixteen As Long
Dim Oeeseventeen As Long
Dim Oeeeighteen As Long
Dim Oeenineteen As Long
Dim Oeetwenty As Long
Dim Peetwelve As Long
Dim Peethirteen As Long
Dim Peefourteen As Long
Dim Peefifteen As Long
Dim Peesixteen As Long
Dim Peeseventeen As Long
Dim Peeeighteen As Long
Dim Peenineteen As Long
Dim Peetwenty As Long
Dim Qeetwelve As Long
Dim Qeethirteen As Long
Dim Qeefourteen As Long
Dim Qeefifteen As Long
Dim Qeesixteen As Long
Dim Qeeseventeen As Long
Dim Qeeeighteen As Long
Dim Qeenineteen As Long
Dim Qeetwenty As Long
Dim Reetwelve As Long
Dim Reethirteen As Long
Dim Reefourteen As Long
Dim Reefifteen As Long
Dim Reesixteen As Long
Dim Reeseventeen As Long
Dim Reeeighteen As Long
Dim Reenineteen As Long
Dim Reetwenty As Long
Dim Seetwelve As Long
Dim Seethirteen As Long
Dim Seefourteen As Long
Dim Seefifteen As Long
Dim Seesixteen As Long
Dim Seeseventeen As Long
Dim Seeeighteen As Long
Dim Seenineteen As Long
Dim Seetwenty As Long


       
        For Each Ws In ActiveWorkbook.Worksheets
        
        If Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - British" Then
    If Ws.Range("D10") = "10-19" Then
        Beetwelve = Beetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - British" Then
    If Ws.Range("D10") = "20-29" Then
        Beethirteen = Beethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - British" Then
    If Ws.Range("D10") = "30-39" Then
        Beefourteen = Beefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - British" Then
    If Ws.Range("D10") = "40-49" Then
        Beefifteen = Beefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - British" Then
    If Ws.Range("D10") = "50-59" Then
        Beesixteen = Beesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - British" Then
    If Ws.Range("D10") = "60-69" Then
        Beeseventeen = Beeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - British" Then
    If Ws.Range("D10") = "70-79" Then
        Beeeighteen = Beeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - British" Then
    If Ws.Range("D10") = "80-89" Then
        Beenineteen = Beenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - British" Then
    If Ws.Range("D10") = "90+" Then
       Beetwenty = Beetwenty + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Irish" Then
    If Ws.Range("D10") = "10-19" Then
        Ceetwelve = Ceetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Irish" Then
    If Ws.Range("D10") = "20-29" Then
        Ceethirteen = Ceethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Irish" Then
    If Ws.Range("D10") = "30-39" Then
        Ceefourteen = Ceefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Irish" Then
    If Ws.Range("D10") = "40-49" Then
        Ceefifteen = Ceefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Irish" Then
    If Ws.Range("D10") = "50-59" Then
        Ceesixteen = Ceesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Irish" Then
    If Ws.Range("D10") = "60-69" Then
        Ceeseventeen = Ceeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Irish" Then
    If Ws.Range("D10") = "70-79" Then
        Ceeeighteen = Ceeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Irish" Then
    If Ws.Range("D10") = "80-89" Then
        Ceeninetee = Ceenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Irish" Then
    If Ws.Range("D10") = "90+" Then
       Ceetwenty = Ceetwenty + 1
ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Other White" Then
    If Ws.Range("D10") = "10-19" Then
        Deetwelve = Deetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Other White" Then
    If Ws.Range("D10") = "20-29" Then
        Deethirteen = Deethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Other White" Then
    If Ws.Range("D10") = "30-39" Then
        Deefourteen = Deefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Other White" Then
    If Ws.Range("D10") = "40-49" Then
        Deefifteen = Deefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Other White" Then
    If Ws.Range("D10") = "50-59" Then
        Deesixteen = Deesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Other White" Then
    If Ws.Range("D10") = "60-69" Then
        Deeseventeen = Deeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Other White" Then
    If Ws.Range("D10") = "70-79" Then
        Deeeighteen = Deeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Other White" Then
    If Ws.Range("D10") = "80-89" Then
        Deeninetee = Deenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - Other White" Then
    If Ws.Range("D10") = "90+" Then
       Deetwenty = Deetwenty + 1
ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black Caribbean" Then
    If Ws.Range("D10") = "10-19" Then
        Eeetwelve = Eeetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black Caribbean" Then
    If Ws.Range("D10") = "20-29" Then
        Eeethirteen = Eeethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black Caribbean" Then
    If Ws.Range("D10") = "30-39" Then
        Eeefourteen = Eeefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black Caribbean" Then
    If Ws.Range("D10") = "40-49" Then
        Eeefifteen = Eeefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black Caribbean" Then
    If Ws.Range("D10") = "50-59" Then
        Eeesixteen = Eeesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black Caribbean" Then
    If Ws.Range("D10") = "60-69" Then
        Eeeseventeen = Eeeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black Caribbean" Then
    If Ws.Range("D10") = "70-79" Then
        Eeeeighteen = Eeeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black Caribbean" Then
    If Ws.Range("D10") = "80-89" Then
        Eeeninetee = Eeenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black Caribbean" Then
    If Ws.Range("D10") = "90+" Then
       Eeetwenty = Eeetwenty + 1
ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black African" Then
    If Ws.Range("D10") = "10-19" Then
        Feetwelve = Feetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black African" Then
    If Ws.Range("D10") = "20-29" Then
        Feethirteen = Feethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black African" Then
    If Ws.Range("D10") = "30-39" Then
        Feefourteen = Feefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black African" Then
    If Ws.Range("D10") = "40-49" Then
        Feefifteen = Feefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black African" Then
    If Ws.Range("D10") = "50-59" Then
        Feesixteen = Feesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black African" Then
    If Ws.Range("D10") = "60-69" Then
        Feeseventeen = Feeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black African" Then
    If Ws.Range("D10") = "70-79" Then
        Feeeighteen = Feeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black African" Then
    If Ws.Range("D10") = "80-89" Then
        Feeninetee = Feenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Black African" Then
    If Ws.Range("D10") = "90+" Then
       Feetwenty = Feetwenty + 1
 ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Asian" Then
    If Ws.Range("D10") = "10-19" Then
        Geetwelve = Geetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Asian" Then
    If Ws.Range("D10") = "20-29" Then
        Geethirteen = Geethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Asian" Then
    If Ws.Range("D10") = "30-39" Then
        Geefourteen = Geefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Asian" Then
    If Ws.Range("D10") = "40-49" Then
        Geefifteen = Geefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Asian" Then
    If Ws.Range("D10") = "50-59" Then
        Geesixteen = Geesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Asian" Then
    If Ws.Range("D10") = "60-69" Then
        Geeseventeen = Geeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Asian" Then
    If Ws.Range("D10") = "70-79" Then
        Geeeighteen = Geeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Asian" Then
    If Ws.Range("D10") = "80-89" Then
        Geeninetee = Geenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - White and Asian" Then
    If Ws.Range("D10") = "90+" Then
       Geetwenty = Geetwenty + 1
ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - Other Mixed" Then
    If Ws.Range("D10") = "10-19" Then
        Heetwelve = Heetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - Other Mixed" Then
    If Ws.Range("D10") = "20-29" Then
        Heethirteen = Heethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - Other Mixed" Then
    If Ws.Range("D10") = "30-39" Then
        Heefourteen = Heefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - Other Mixed" Then
    If Ws.Range("D10") = "40-49" Then
        Heefifteen = Heefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - Other Mixed" Then
    If Ws.Range("D10") = "50-59" Then
        Heesixteen = Heesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - Other Mixed" Then
    If Ws.Range("D10") = "60-69" Then
        Heeseventeen = Heeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - Other Mixed" Then
    If Ws.Range("D10") = "70-79" Then
        Heeeighteen = Heeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - Other Mixed" Then
    If Ws.Range("D10") = "80-89" Then
        Heeninetee = Heenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Mixed - Other Mixed" Then
    If Ws.Range("D10") = "90+" Then
       Heetwenty = Heetwenty + 1
ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Indian" Then
    If Ws.Range("D10") = "10-19" Then
        ieetwelve = ieetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Indian" Then
    If Ws.Range("D10") = "20-29" Then
        ieethirteen = ieethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Indian" Then
    If Ws.Range("D10") = "30-39" Then
        ieefourteen = ieefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Indian" Then
    If Ws.Range("D10") = "40-49" Then
        ieefifteen = ieefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Indian" Then
    If Ws.Range("D10") = "50-59" Then
        ieesixteen = ieesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Indian" Then
    If Ws.Range("D10") = "60-69" Then
        ieeseventeen = ieeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Indian" Then
    If Ws.Range("D10") = "70-79" Then
        ieeeighteen = ieeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Indian" Then
    If Ws.Range("D10") = "80-89" Then
        ieeninetee = ieenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Indian" Then
    If Ws.Range("D10") = "90+" Then
       ieetwenty = ieetwenty + 1
ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Pakistani" Then
    If Ws.Range("D10") = "10-19" Then
        Jeetwelve = Jeetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Pakistani" Then
    If Ws.Range("D10") = "20-29" Then
        Jeethirteen = Jeethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Pakistani" Then
    If Ws.Range("D10") = "30-39" Then
        Jeefourteen = Jeefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Pakistani" Then
    If Ws.Range("D10") = "40-49" Then
        Jeefifteen = Jeefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Pakistani" Then
    If Ws.Range("D10") = "50-59" Then
        Jeesixteen = Jeesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Pakistani" Then
    If Ws.Range("D10") = "60-69" Then
        Jeeseventeen = Jeeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Pakistani" Then
    If Ws.Range("D10") = "70-79" Then
        Jeeeighteen = Jeeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Pakistani" Then
    If Ws.Range("D10") = "80-89" Then
        Jeeninetee = Jeenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Pakistani" Then
    If Ws.Range("D10") = "90+" Then
       Jeetwenty = Jeetwenty + 1
 ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Bangladeshi " Then
    If Ws.Range("D10") = "10-19" Then
        Keetwelve = Keetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Bangladeshi " Then
    If Ws.Range("D10") = "20-29" Then
        Keethirteen = Keethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Bangladeshi " Then
    If Ws.Range("D10") = "30-39" Then
        Keefourteen = Keefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Bangladeshi " Then
    If Ws.Range("D10") = "40-49" Then
        Keefifteen = Keefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Bangladeshi " Then
    If Ws.Range("D10") = "50-59" Then
        Keesixteen = Keesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Bangladeshi " Then
    If Ws.Range("D10") = "60-69" Then
        Keeseventeen = Keeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Bangladeshi " Then
    If Ws.Range("D10") = "70-79" Then
        Keeeighteen = Keeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Bangladeshi " Then
    If Ws.Range("D10") = "80-89" Then
        Keeninetee = Keenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Bangladeshi " Then
    If Ws.Range("D10") = "90+" Then
       Keetwenty = Keetwenty + 1
ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Other Asian" Then
    If Ws.Range("D10") = "10-19" Then
        Leetwelve = Leetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Other Asian" Then
    If Ws.Range("D10") = "20-29" Then
        Leethirteen = Leethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Other Asian" Then
    If Ws.Range("D10") = "30-39" Then
        Leefourteen = Leefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Other Asian" Then
    If Ws.Range("D10") = "40-49" Then
        Leefifteen = Leefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Other Asian" Then
    If Ws.Range("D10") = "50-59" Then
        Leesixteen = Leesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Other Asian" Then
    If Ws.Range("D10") = "60-69" Then
        Leeseventeen = Leeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Other Asian" Then
    If Ws.Range("D10") = "70-79" Then
        Leeeighteen = Leeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Other Asian" Then
    If Ws.Range("D10") = "80-89" Then
        Leeninetee = Leenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Other Asian" Then
    If Ws.Range("D10") = "90+" Then
       Leetwenty = Leetwenty + 1
ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = " Black - Caribbean" Then
    If Ws.Range("D10") = "10-19" Then
        Meetwelve = Meetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = " Black - Caribbean" Then
    If Ws.Range("D10") = "20-29" Then
        Meethirteen = Meethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = " Black - Caribbean" Then
    If Ws.Range("D10") = "30-39" Then
        Meefourteen = Meefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = " Black - Caribbean" Then
    If Ws.Range("D10") = "40-49" Then
        Meefifteen = Meefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = " Black - Caribbean" Then
    If Ws.Range("D10") = "50-59" Then
        Meesixteen = Meesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = " Black - Caribbean" Then
    If Ws.Range("D10") = "60-69" Then
        Meeseventeen = Meeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = " Black - Caribbean" Then
    If Ws.Range("D10") = "70-79" Then
        Meeeighteen = Meeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = " Black - Caribbean" Then
    If Ws.Range("D10") = "80-89" Then
        Meeninetee = Meenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = " Black - Caribbean" Then
    If Ws.Range("D10") = "90+" Then
       Meetwenty = Meetwenty + 1
 ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - African" Then
    If Ws.Range("D10") = "10-19" Then
        Neetwelve = Neetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - African" Then
    If Ws.Range("D10") = "20-29" Then
        Neethirteen = Neethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - African" Then
    If Ws.Range("D10") = "30-39" Then
        Neefourteen = Neefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - African" Then
    If Ws.Range("D10") = "40-49" Then
        Neefifteen = Neefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - African" Then
    If Ws.Range("D10") = "50-59" Then
        Neesixteen = Neesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - African" Then
    If Ws.Range("D10") = "60-69" Then
        Neeseventeen = Neeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - African" Then
    If Ws.Range("D10") = "70-79" Then
        Neeeighteen = Neeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - African" Then
    If Ws.Range("D10") = "80-89" Then
        Neeninetee = Neenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - African" Then
    If Ws.Range("D10") = "90+" Then
       Neetwenty = Neetwenty + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - Other Black" Then
    If Ws.Range("D10") = "10-19" Then
        Oeetwelve = Oeetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - Other Black" Then
    If Ws.Range("D10") = "20-29" Then
        Oeethirteen = Oeethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - Other Black" Then
    If Ws.Range("D10") = "30-39" Then
        Oeefourteen = Oeefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - Other Black" Then
    If Ws.Range("D10") = "40-49" Then
        Oeefifteen = Oeefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - Other Black" Then
    If Ws.Range("D10") = "50-59" Then
        Oeesixteen = Oeesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - Other Black" Then
    If Ws.Range("D10") = "60-69" Then
        Oeeseventeen = Oeeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - Other Black" Then
    If Ws.Range("D10") = "70-79" Then
        Oeeeighteen = Oeeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - Other Black" Then
    If Ws.Range("D10") = "80-89" Then
        Oeeninetee = Oeenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Black - Other Black" Then
    If Ws.Range("D10") = "90+" Then
       Oeetwenty = Oeetwenty + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Chinese" Then
    If Ws.Range("D10") = "10-19" Then
        Peetwelve = Peetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Chinese" Then
    If Ws.Range("D10") = "20-29" Then
        Peethirteen = Peethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Chinese" Then
    If Ws.Range("D10") = "30-39" Then
        Peefourteen = Peefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Chinese" Then
    If Ws.Range("D10") = "40-49" Then
        Peefifteen = Peefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Chinese" Then
    If Ws.Range("D10") = "50-59" Then
        Peesixteen = Peesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Chinese" Then
    If Ws.Range("D10") = "60-69" Then
        Peeseventeen = Peeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Chinese" Then
    If Ws.Range("D10") = "70-79" Then
        Peeeighteen = Peeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Chinese" Then
    If Ws.Range("D10") = "80-89" Then
        Peeninetee = Peenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Asian - Chinese" Then
    If Ws.Range("D10") = "90+" Then
       Peetwenty = Peetwenty + 1
ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Any other ethnic group (including Arab)" Then
    If Ws.Range("D10") = "10-19" Then
        Qeetwelve = Qeetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Any other ethnic group (including Arab)" Then
    If Ws.Range("D10") = "20-29" Then
        Qeethirteen = Qeethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Any other ethnic group (including Arab)" Then
    If Ws.Range("D10") = "30-39" Then
        Qeefourteen = Qeefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Any other ethnic group (including Arab)" Then
    If Ws.Range("D10") = "40-49" Then
        Qeefifteen = Qeefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Any other ethnic group (including Arab)" Then
    If Ws.Range("D10") = "50-59" Then
        Qeesixteen = Qeesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Any other ethnic group (including Arab)" Then
    If Ws.Range("D10") = "60-69" Then
        Qeeseventeen = Qeeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Any other ethnic group (including Arab)" Then
    If Ws.Range("D10") = "70-79" Then
        Qeeeighteen = Qeeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Any other ethnic group (including Arab)" Then
    If Ws.Range("D10") = "80-89" Then
        Qeeninetee = Qeenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Any other ethnic group (including Arab)" Then
    If Ws.Range("D10") = "90+" Then
       Qeetwenty = Qeetwenty + 1
ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups" Then
    If Ws.Range("D10") = "10-19" Then
        Reetwelve = Reetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups" Then
    If Ws.Range("D10") = "20-29" Then
        Reethirteen = Reethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups" Then
    If Ws.Range("D10") = "30-39" Then
        Reefourteen = Reefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups" Then
    If Ws.Range("D10") = "40-49" Then
        Reefifteen = Reefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups" Then
    If Ws.Range("D10") = "50-59" Then
        Reesixteen = Reesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups" Then
    If Ws.Range("D10") = "60-69" Then
        Reeseventeen = Reeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups" Then
    If Ws.Range("D10") = "70-79" Then
        Reeeighteen = Reeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups" Then
    If Ws.Range("D10") = "80-89" Then
        Reeninetee = Reenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups" Then
    If Ws.Range("D10") = "90+" Then
       Reetwenty = Reetwenty + 1
         ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups - Patient Refused" Then
    If Ws.Range("D10") = "10-19" Then
        Seetwelve = Seetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups - Patient Refused" Then
    If Ws.Range("D10") = "20-29" Then
        Seethirteen = Seethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups - Patient Refused" Then
    If Ws.Range("D10") = "30-39" Then
        Seefourteen = Seefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups - Patient Refused" Then
    If Ws.Range("D10") = "40-49" Then
        Seefifteen = Seefifteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups - Patient Refused" Then
    If Ws.Range("D10") = "50-59" Then
        Seesixteen = Seesixteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups - Patient Refused" Then
    If Ws.Range("D10") = "60-69" Then
        Seeseventeen = Seeseventeen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups - Patient Refused" Then
    If Ws.Range("D10") = "70-79" Then
        Seeeighteen = Seeeighteen + 1
       ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups - Patient Refused" Then
    If Ws.Range("D10") = "80-89" Then
        Seeninetee = Seenineteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "Other Ethnic Groups - Patient Refused" Then
    If Ws.Range("D10") = "90+" Then
       Seetwenty = Seetwenty + 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
End If
End If
End If
End If
End If




Next Ws




Cells(12, 2).Value = Beetwelve
Cells(13, 2).Value = Beethirteen
Cells(14, 2).Value = Beefourteen
Cells(15, 2).Value = Beefifteen
Cells(16, 2).Value = Beesixteen
Cells(17, 2).Value = Beeseventeen
Cells(18, 2).Value = Beeeighteen
Cells(19, 2).Value = Beenineteen
Cells(20, 2).Value = Beetwenty
Cells(12, 3).Value = Ceetwelve
Cells(13, 3).Value = Ceethirteen
Cells(14, 3).Value = Ceefourteen
Cells(15, 3).Value = Ceefifteen
Cells(16, 3).Value = Ceesixteen
Cells(17, 3).Value = Ceeseventeen
Cells(18, 3).Value = Ceeeighteen
Cells(19, 3).Value = Ceenineteen
Cells(20, 3).Value = Ceetwenty
Cells(12, 4).Value = Deetwelve
Cells(13, 4).Value = Deethirteen
Cells(14, 4).Value = Deefourteen
Cells(15, 4).Value = Deefifteen
Cells(16, 4).Value = Deesixteen
Cells(17, 4).Value = Deeseventeen
Cells(18, 4).Value = Deeeighteen
Cells(19, 4).Value = Deenineteen
Cells(20, 4).Value = Deetwenty
Cells(12, 5).Value = Eeetwelve
Cells(13, 5).Value = Eeethirteen
Cells(14, 5).Value = Eeefourteen
Cells(15, 5).Value = Eeefifteen
Cells(16, 5).Value = Eeesixteen
Cells(17, 5).Value = Eeeseventeen
Cells(18, 5).Value = Eeeeighteen
Cells(19, 5).Value = Eeenineteen
Cells(20, 5).Value = Eeetwenty
Cells(12, 6).Value = Feetwelve
Cells(13, 6).Value = Feethirteen
Cells(14, 6).Value = Feefourteen
Cells(15, 6).Value = Feefifteen
Cells(16, 6).Value = Feesixteen
Cells(17, 6).Value = Feeseventeen
Cells(18, 6).Value = Feeeighteen
Cells(19, 6).Value = Feenineteen
Cells(20, 6).Value = Feetwenty
Cells(12, 7).Value = Geetwelve
Cells(13, 7).Value = Geethirteen
Cells(14, 7).Value = Geefourteen
Cells(15, 7).Value = Geefifteen
Cells(16, 7).Value = Geesixteen
Cells(17, 7).Value = Geeseventeen
Cells(18, 7).Value = Geeeighteen
Cells(19, 7).Value = Geenineteen
Cells(20, 7).Value = Geetwenty
Cells(12, 8).Value = Heetwelve
Cells(13, 8).Value = Heethirteen
Cells(14, 8).Value = Heefourteen
Cells(15, 8).Value = Heefifteen
Cells(16, 8).Value = Heesixteen
Cells(17, 8).Value = Heeseventeen
Cells(18, 8).Value = Heeeighteen
Cells(19, 8).Value = Heenineteen
Cells(20, 8).Value = Heetwenty
Cells(12, 9).Value = ieetwelve
Cells(13, 9).Value = ieethirteen
Cells(14, 9).Value = ieefourteen
Cells(15, 9).Value = ieefifteen
Cells(16, 9).Value = ieesixteen
Cells(17, 9).Value = ieeseventeen
Cells(18, 9).Value = ieeeighteen
Cells(19, 9).Value = ieenineteen
Cells(20, 9).Value = ieetwenty
Cells(12, 10).Value = Jeetwelve
Cells(13, 10).Value = Jeethirteen
Cells(14, 10).Value = Jeefourteen
Cells(15, 10).Value = Jeefifteen
Cells(16, 10).Value = Jeesixteen
Cells(17, 10).Value = Jeeseventeen
Cells(18, 10).Value = Jeeeighteen
Cells(19, 10).Value = Jeenineteen
Cells(20, 10).Value = Jeetwenty
Cells(12, 11).Value = Keetwelve
Cells(13, 11).Value = Keethirteen
Cells(14, 11).Value = Keefourteen
Cells(15, 11).Value = Keefifteen
Cells(16, 11).Value = Keesixteen
Cells(17, 11).Value = Keeseventeen
Cells(18, 11).Value = Keeeighteen
Cells(19, 11).Value = Keenineteen
Cells(20, 11).Value = Keetwenty
Cells(12, 12).Value = Leetwelve
Cells(13, 12).Value = Leethirteen
Cells(14, 12).Value = Leefourteen
Cells(15, 12).Value = Leefifteen
Cells(16, 12).Value = Leesixteen
Cells(17, 12).Value = Leeseventeen
Cells(18, 12).Value = Leeeighteen
Cells(19, 12).Value = Leenineteen
Cells(20, 12).Value = Leetwenty
Cells(12, 13).Value = Meetwelve
Cells(13, 13).Value = Meethirteen
Cells(14, 13).Value = Meefourteen
Cells(15, 13).Value = Meefifteen
Cells(16, 13).Value = Meesixteen
Cells(17, 13).Value = Meeseventeen
Cells(18, 13).Value = Meeeighteen
Cells(19, 13).Value = Meenineteen
Cells(20, 13).Value = Meetwenty
Cells(12, 14).Value = Neetwelve
Cells(13, 14).Value = Neethirteen
Cells(14, 14).Value = Neefourteen
Cells(15, 14).Value = Neefifteen
Cells(16, 14).Value = Neesixteen
Cells(17, 14).Value = Neeseventeen
Cells(18, 14).Value = Neeeighteen
Cells(19, 14).Value = Neenineteen
Cells(20, 14).Value = Neetwenty
Cells(12, 15).Value = Oeetwelve
Cells(13, 15).Value = Oeethirteen
Cells(14, 15).Value = Oeefourteen
Cells(15, 15).Value = Oeefifteen
Cells(16, 15).Value = Oeesixteen
Cells(17, 15).Value = Oeeseventeen
Cells(18, 15).Value = Oeeeighteen
Cells(19, 15).Value = Oeenineteen
Cells(20, 15).Value = Oeetwenty
Cells(12, 16).Value = Peetwelve
Cells(13, 16).Value = Peethirteen
Cells(14, 16).Value = Peefourteen
Cells(15, 16).Value = Peefifteen
Cells(16, 16).Value = Peesixteen
Cells(17, 16).Value = Peeseventeen
Cells(18, 16).Value = Peeeighteen
Cells(19, 16).Value = Peenineteen
Cells(20, 16).Value = Peetwenty
Cells(12, 17).Value = Qeetwelve
Cells(13, 17).Value = Qeethirteen
Cells(14, 17).Value = Qeefourteen
Cells(15, 17).Value = Qeefifteen
Cells(16, 17).Value = Qeesixteen
Cells(17, 17).Value = Qeeseventeen
Cells(18, 17).Value = Qeeeighteen
Cells(19, 17).Value = Qeenineteen
Cells(20, 17).Value = Qeetwenty
Cells(12, 18).Value = Reetwelve
Cells(13, 18).Value = Reethirteen
Cells(14, 18).Value = Reefourteen
Cells(15, 18).Value = Reefifteen
Cells(16, 18).Value = Reesixteen
Cells(17, 18).Value = Reeseventeen
Cells(18, 18).Value = Reeeighteen
Cells(19, 18).Value = Reenineteen
Cells(20, 18).Value = Reetwenty
Cells(12, 19).Value = Seetwelve
Cells(13, 19).Value = Seethirteen
Cells(14, 19).Value = Seefourteen
Cells(15, 19).Value = Seefifteen
Cells(16, 19).Value = Seesixteen
Cells(17, 19).Value = Seeseventeen
Cells(18, 19).Value = Seeeighteen
Cells(19, 19).Value = Seenineteen
Cells(20, 19).Value = Seetwenty
 
Upvote 0
It's the same principle - you need to stop repeating the gender and ethnicity tests for each age - i.e. don't use this:
Code:
        If Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - British" Then
    If Ws.Range("D10") = "10-19" Then
        Beetwelve = Beetwelve + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - British" Then
    If Ws.Range("D10") = "20-29" Then
        Beethirteen = Beethirteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - British" Then
    If Ws.Range("D10") = "30-39" Then
        Beefourteen = Beefourteen + 1
        ElseIf Ws.Range("F6") = "Male" Then
    If Ws.Range("F7") = "White - British" Then
    If Ws.Range("D10") = "40-49" Then
        Beefifteen = Beefifteen + 1

but use this:
Code:
        If Ws.Range("F6") = "Male" Then
        
            If Ws.Range("F7") = "White - British" Then
            
                If Ws.Range("D10") = "10-19" Then
                    Beetwelve = Beetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Beethirteen = Beethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Beefourteen = Beefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Beefifteen = Beefifteen + 1
                    ' further ElseIf statements for each age
                End If
                
            ElseIf Ws.Range("F7") = "White - Irish" Then
            
                'repeat age tests
            End If
            
        ElseIf Ws.Range("F6") = "Female" Then
        
            ' repeat ethnicity then age tests
        End If


By the way, I think you could simplify this with summary formulas on each sheet, or a better layout.
 
Upvote 0
Thanks for sticking with this Rory:

So I've done what I thought was right for the 'Male' Routine and then decided to divide the other genders into different subroutines:

Is there something wrong with the following? It's not quite there.

many thanks,

Code:
For Each Ws In ActiveWorkbook.Worksheets





If Ws.Range("F6") = "Male" Then
        
            If Ws.Range("F7") = "White - British" Then
            
                If Ws.Range("D10") = "10-19" Then
                    Beetwelve = Beetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Beethirteen = Beethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Beefourteen = Beefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Beefifteen = Beefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Beesixteen = Beesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Beeseventeen = Beeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Beeeighteen = Beeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Beenineteen = Beenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Beetwenty = Beetwenty + 1
                   
                End If
                End If
                
            ElseIf Ws.Range("F7") = "White - Irish" Then


        If Ws.Range("D10") = "10-19" Then
                    Ceetwelve = Ceetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Ceethirteen = Ceethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Ceefourteen = Ceefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Ceefifteen = Ceefifteen + 1
                 ElseIf Ws.Range("D10") = "50-59" Then
                    Ceesixteen = Ceesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Ceeseventeen = Ceeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Ceeeighteen = Ceeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Ceenineteen = Ceenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Ceetwenty = Ceetwenty + 1


        End If
                
            ElseIf Ws.Range("F7") = "White - Other White" Then


        If Ws.Range("D10") = "10-19" Then
                    Deetwelve = Deetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Deethirteen = Deethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Deefourteen = Deefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Deefifteen = Deefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Deesixteen = Deesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Deeseventeen = Deeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Deeeighteen = Deeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Deenineteen = Deenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Deetwenty = Deetwenty + 1


        End If
                
            ElseIf Ws.Range("F7") = "Mixed - White and Black Caribbean" Then


        If Ws.Range("D10") = "10-19" Then
                    Eeetwelve = Eeetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Eeethirteen = Eeethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Eeefourteen = Eeefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Eeefifteen = Eeefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Eeesixteen = Eeesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Eeeseventeen = Eeeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Eeeeighteen = Eeeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Eeenineteen = Eeenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Eeetwenty = Eeetwenty + 1


        End If
                
            ElseIf Ws.Range("F7") = "Mixed - White and Black African" Then


        If Ws.Range("D10") = "10-19" Then
                    Feetwelve = Feetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Feethirteen = Feethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Feefourteen = Feefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Feefifteen = Feefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Feesixteen = Feesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Feeseventeen = Feeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Feeeighteen = Feeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Feenineteen = Feenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Feetwenty = Feetwenty + 1


        End If
                
            ElseIf Ws.Range("F7") = "Mixed - White and Asian" Then


        If Ws.Range("D10") = "10-19" Then
                    Geetwelve = Geetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Geethirteen = Geethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Geefourteen = Geefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Geefifteen = Geefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Geesixteen = Geesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Geeseventeen = Geeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Geeeighteen = Geeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Geenineteen = Geenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Geetwenty = Geetwenty + 1


        End If
                
            ElseIf Ws.Range("F7") = "Mixed - Other Mixed" Then


        If Ws.Range("D10") = "10-19" Then
                    Heetwelve = Heetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Heethirteen = Heethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Heefourteen = Heefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Heefifteen = Heefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Heesixteen = Heesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Heeseventeen = Heeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Heeeighteen = Heeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Heenineteen = Heenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Heetwenty = Heetwenty + 1


        End If
                
            ElseIf Ws.Range("F7") = "Asian - Indian" Then


        If Ws.Range("D10") = "10-19" Then
                    ieetwelve = ieetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    ieethirteen = ieethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    ieefourteen = ieefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    ieefifteen = ieefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    ieesixteen = ieesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    ieeseventeen = ieeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    ieeeighteen = ieeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    ieenineteen = ieenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    ieetwenty = ieetwenty + 1


        End If
                
            ElseIf Ws.Range("F7") = "Asian - Pakistani" Then


        If Ws.Range("D10") = "10-19" Then
                    Jeetwelve = Jeetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Jeethirteen = Jeethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Jeefourteen = Jeefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Jeefifteen = Jeefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Jeesixteen = Jeesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Jeeseventeen = Jeeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Jeeeighteen = Jeeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Jeenineteen = Jeenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Jeetwenty = Jeetwenty + 1


        End If
                
            ElseIf Ws.Range("F7") = "Asian - Bangladeshi" Then


        If Ws.Range("D10") = "10-19" Then
                    Keetwelve = Keetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Keethirteen = Keethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Keefourteen = Keefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Keefifteen = Keefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Keesixteen = Keesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Keeseventeen = Keeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Keeeighteen = Keeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Keenineteen = Keenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Keetwenty = Keetwenty + 1


        End If
                
            ElseIf Ws.Range("F7") = "Asian - Other Asian" Then


        If Ws.Range("D10") = "10-19" Then
                    Leetwelve = Leetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Leethirteen = Leethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Leefourteen = Leefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Leefifteen = Leefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Leesixteen = Leesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Leeseventeen = Leeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Leeeighteen = Leeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Leenineteen = Leenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Leetwenty = Leetwenty + 1


        End If
                
            ElseIf Ws.Range("F7") = " Black - Caribbean" Then


        If Ws.Range("D10") = "10-19" Then
                    Meetwelve = Meetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Meethirteen = Meethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Meefourteen = Meefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Meefifteen = Meefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Meesixteen = Meesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Meeseventeen = Meeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Meeeighteen = Meeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Meenineteen = Meenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Meetwenty = Meetwenty + 1


        End If
                
            ElseIf Ws.Range("F7") = "Black - African" Then


        If Ws.Range("D10") = "10-19" Then
                    Neetwelve = Neetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Neethirteen = Neethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Neefourteen = Neefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Neefifteen = Neefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Neesixteen = Neesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Neeseventeen = Neeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Neeeighteen = Neeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Neenineteen = Neenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Neetwenty = Neetwenty + 1


        End If
                
            ElseIf Ws.Range("F7") = "Black - Other Black" Then


        If Ws.Range("D10") = "10-19" Then
                    Oeetwelve = Oeetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Oeethirteen = Oeethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Oeefourteen = Oeefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Oeefifteen = Oeefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Oeesixteen = Oeesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Oeeseventeen = Oeeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Oeeeighteen = Oeeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Oeenineteen = Oeenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Oeetwenty = Oeetwenty + 1


        End If
                
            ElseIf Ws.Range("F7") = "Asian - Chinese" Then


        If Ws.Range("D10") = "10-19" Then
                    Peetwelve = Peetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Peethirteen = Peethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Peefourteen = Peefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Peefifteen = Peefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Peesixteen = Peesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Peeseventeen = Peeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Peeeighteen = Peeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Peenineteen = Peenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Peetwenty = Peetwenty + 1
        End If
                
            ElseIf Ws.Range("F7") = "Any other ethnic group (including Arab)" Then


        If Ws.Range("D10") = "10-19" Then
                    Qeetwelve = Qeetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Qeethirteen = Qeethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Qeefourteen = Qeefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Qeefifteen = Qeefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Qeesixteen = Qeesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Qeeseventeen = Qeeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Qeeeighteen = Qeeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Qeenineteen = Qeenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Qeetwenty = Qeetwenty + 1


        End If
                
            ElseIf Ws.Range("F7") = "Other Ethnic Groups" Then


        If Ws.Range("D10") = "10-19" Then
                    Reetwelve = Reetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Reethirteen = Reethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Reefourteen = Reefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Reefifteen = Reefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Reesixteen = Reesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Reeseventeen = Reeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Reeeighteen = Reeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Reenineteen = Reenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Reetwenty = Reetwenty + 1


        End If
                
            ElseIf Ws.Range("F7") = "Other Ethnic Groups - Patient Refused" Then


        If Ws.Range("D10") = "10-19" Then
                    Seetwelve = Seetwelve + 1
                ElseIf Ws.Range("D10") = "20-29" Then
                    Seethirteen = Seethirteen + 1
                ElseIf Ws.Range("D10") = "30-39" Then
                    Seefourteen = Seefourteen + 1
                ElseIf Ws.Range("D10") = "40-49" Then
                    Seefifteen = Seefifteen + 1
        ElseIf Ws.Range("D10") = "50-59" Then
                    Seesixteen = Seesixteen + 1
                ElseIf Ws.Range("D10") = "60-69" Then
                    Seeseventeen = Seeseventeen + 1
                ElseIf Ws.Range("D10") = "70-79" Then
                    Seeeighteen = Seeeighteen + 1
                ElseIf Ws.Range("D10") = "80-89" Then
                    Seenineteen = Seenineteen + 1
        ElseIf Ws.Range("D10") = "80-89" Then
                    Seetwenty = Seetwenty + 1


        End If


    End If


Next Ws
 
Upvote 0
What exactly does "not quite there" mean?
 
Upvote 0
What exactly does "not quite there" mean?

Haha, sorry..

It's still not pulling through correctly to the place where the cells output

Specifically, the issue appears to be with the ethnicities; White British works but the moment I change ethnicity to something else, it's not being picked up.

Therefore I presume I've structured something wrong following the first set of ages and my 'End Ifs' ?

Thanks!
 
Upvote 0
You have two End If lines after the first set of age checks, so you are ending the age check and the ethnicity check. One of them needs to be moved.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top