+ Reply to Thread
Results 1 to 3 of 3

Coding CountIf Statements

  1. #1
    Registered User
    Join Date
    04-03-2007
    Posts
    21

    Coding CountIf Statements

    I need help getting a CountIf formula to work correctly in VBA. I am working with marketing data which shows hundreds of responses people gave to multiple choice questions. In each row I have the respondants name, the question asked, and the answer given. I am building a summary sheet that shows each question asked, the possible answers, and the number of times each response was given for each question. The end result I need is a formula that gives the number times each answer was given per question.

    I have a subroute which is deternines the QuestionRangeStart and the QuestionRangeEnd for the current question. At that point I try to enter the CountIf formula using these variables. In the end the formula should read as follows:

    =COUNTIF(ControlTemp!G11:G96,"=" & A2)
    (QuestionRangeStart = 11, Question Range End = 96, Lookup Value = Cell A2.

    Because I am new to VBA I tried to create this formula by recording a macro and substituting in the variable names. The current code reads as follows:

    Please Login or Register  to view this content.
    The problem I run into is that when I enter those variables into the CountIf formula it seems to increment the value each time instead of sticking to the variable. The range should be exactly the same for each response line. Any help would be greatly appreciated.

  2. #2
    Registered User
    Join Date
    04-03-2007
    Posts
    21

    Work Around Discovered

    I've been playing with this for the last day and have some ideas. I didn't see any responses, so I figured I'd post what I found in case anyone else runs into the same issue.

    When I recorded the macro to get the formula base for the VBA, the recorded gave me the format you see in the original posting. I don't really understand the [r] and [c] bit, however it appears to be taking the current row. So... to get it to use just the variable I was able to modify the code and have it substract the current row number. Below is an excerpt from the code I ended up using. Its not the cleanest way to do this, but it worked. Hope this helps someone else.

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    The R and the C come from the R1C1 Reference Style. If you go into Tools > Options > General, the R1C1 reference style box is probably checked. This is simply a different way to reference a cell.

    If the box is checked, you might want to uncheck it and rerecord your macro. It might make things a little easier to understand.

    Jeff

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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