+ Reply to Thread
Results 1 to 6 of 6

[Solved] Array Count help (newbie)

Hybrid View

zaoth [Solved] Array Count help... 07-17-2014, 11:27 AM
Vikas_Gautam Re: Array Count help (newbie) 07-17-2014, 11:43 AM
zaoth Re: Array Count help (newbie) 07-17-2014, 11:49 AM
Arkadi Re: Array Count help (newbie) 07-17-2014, 12:00 PM
zaoth Re: Array Count help (newbie) 07-17-2014, 01:20 PM
Arkadi Re: [Solved] Array Count help... 07-17-2014, 01:57 PM
  1. #1
    Registered User
    Join Date
    07-17-2014
    Location
    uk
    MS-Off Ver
    2010
    Posts
    6

    [Solved] Array Count help (newbie)

    Hi,

    I have an array of 300 respondents and their answers to 5 questions.

    Basically what I want to do is output next to the respondent number how many times they said X across all questions, for example Person 1, 2. Person 2, 4.
    This is what my array looks like so far, I have it being output just as a check that it works.

    Dim Arr() As Variant
    Dim wstd As Worksheet
    Dim wstska As Worksheet
    Set wstd = Sheets("td")
    Set wstska = Sheets("taska")
    Arr = wstd.Range("A1:G301")
    wstska.Range("a1:g301") = Arr
    A countif is probably needed or something along those lines with a loop. I have no idea what to do next. I have looked up countif's and they just use the formula but I would like to do it in the VBA code.

    Here is a Sample: sample.xlsm

    Thanks.
    Last edited by zaoth; 07-17-2014 at 01:20 PM. Reason: Added sample

  2. #2
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Array Count help (newbie)

    provide a sample workbook....
    That will help us to help you better...




    Don't forget to click *

  3. #3
    Registered User
    Join Date
    07-17-2014
    Location
    uk
    MS-Off Ver
    2010
    Posts
    6

    Re: Array Count help (newbie)

    Quote Originally Posted by Vikas_Gautam View Post
    provide a sample workbook....
    That will help us to help you better...




    Don't forget to click *
    Added a sample now. Thanks for the quick reply.

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Array Count help (newbie)

    Suggestion....

    dim these two to use as one dimensional array of x per user, and counter for a loop:

    Dim arrcount() As Variant
    Dim counter As Long
    then loop through the users to store their "X"'s:

    ReDim arrcount(1 To UBound(Arr, 1)) 'this is to set up your array of responses with the number of records in your first array
    For i = 1 To UBound(Arr, 1) 'loop thrhough number of respondents
        counter = 0 'counter that starts at zero each time, will increment when response matches what you are looking for
        For j = 2 To 7 'to check the cells in columns B to G as per your defined range
            If wstd.Cells(i, j).Value = "X" Then counter = counter + 1 'increment counter if answer matches criteria ("X")
        Next j
        arrcount(i) = counter 'stores number of X's for user "i"
    Next i
    What you do with that info afterwards is up to you, but you can loop through users with another for loop....

    for k = 1 to ubound(arrcount) 
         do stuff
    next k
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  5. #5
    Registered User
    Join Date
    07-17-2014
    Location
    uk
    MS-Off Ver
    2010
    Posts
    6

    Re: Array Count help (newbie)

    Quote Originally Posted by Arkadi View Post
    Suggestion....

    dim these two to use as one dimensional array of x per user, and counter for a loop:

    Dim arrcount() As Variant
    Dim counter As Long
    then loop through the users to store their "X"'s:

    ReDim arrcount(1 To UBound(Arr, 1)) 'this is to set up your array of responses with the number of records in your first array
    For i = 1 To UBound(Arr, 1) 'loop thrhough number of respondents
        counter = 0 'counter that starts at zero each time, will increment when response matches what you are looking for
        For j = 2 To 7 'to check the cells in columns B to G as per your defined range
            If wstd.Cells(i, j).Value = "X" Then counter = counter + 1 'increment counter if answer matches criteria ("X")
        Next j
        arrcount(i) = counter 'stores number of X's for user "i"
    Next i
    What you do with that info afterwards is up to you, but you can loop through users with another for loop....

    for k = 1 to ubound(arrcount) 
         do stuff
    next k
    Thanks for the help. Had to tweak it a bit to get it working properly but your guidance helped!

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: [Solved] Array Count help (newbie)

    Yeah didn't have your actual sheet to work with, but figured you'd have enough there to work with
    Glad it worked out for you, nicely done.

    Edit OOOPS! missed you did put in a sample sheet
    Last edited by Arkadi; 07-17-2014 at 03:00 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. newbie: simple column frequency count excel2010
    By wuxx in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 02-24-2014, 06:11 AM
  2. newbie question on multi-dimensional array
    By sammus in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 04-02-2006, 10:11 PM
  3. VB Newbie - Counting occurences in array
    By SJC in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-28-2005, 10:40 AM
  4. (Newbie) Copying values from an array to the worksheet
    By Srdjan Kovacevic in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2005, 11:05 AM
  5. newbie: count total of number in strings
    By cuongvt in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-15-2005, 11:05 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