+ Reply to Thread
Results 1 to 15 of 15

If Problems.....

  1. #1
    Registered User
    Join Date
    05-28-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Question If Problems.....

    Hi I am trying to write a macro that will put text into the nominated cell. The macro needs to look at 3 cells in a range, on my worksheet they are D35, D36 and D37. If one of these cells contains the phrase "Hypothesis Null Rejected" then the macro should return the Phrase A. If all three cells = "hypothesis null not rejected" then the macro should return phrase B.

    My problem is that I can't get it to look at all three, it only returns a phrase based on the 3rd cell. I don't know how to fix this.

    This is the code I am using;

    Please Login or Register  to view this content.
    I should probably tell you that I have only been writing VBA code for exactly a week now. I am self-taught and basically fumbling in the dark, so any help would be great!!!!!
    Last edited by Macnautor; 05-28-2012 at 02:38 PM.

  2. #2
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: If Problems.....

    Without looking past the 2nd line:

    Remove the quotes from the numbers 35 and 37

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: If Problems.....

    Try this
    Please Login or Register  to view this content.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: If Problems.....

    And you haven't Dim'ed i.

  5. #5
    Registered User
    Join Date
    05-28-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: If Problems.....

    I have tried both suggestions and this is still returning the phrase based on the value in D37.

    When you say Dim'ed i? what exactly do you mean?

  6. #6
    Registered User
    Join Date
    05-28-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: If Problems.....

    I have also tried this code;

    Please Login or Register  to view this content.

  7. #7
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: If Problems.....

    When you say Dim'ed i? what exactly do you mean?
    You 'declared': Result As String, Conc As String
    but you didn't 'declare': i as Integer

  8. #8
    Registered User
    Join Date
    05-28-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: If Problems.....

    Thanks for your help so far Cutter, but this has not helped, it still is only chaging the value of B40 based on the result from the last "i" in the group C37.

  9. #9
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: If Problems.....

    Why don't you just have a formula sitting in cell B40?

    Like:
    =IF(COUNTIF(D35:D37,"Hypothesis Null Rejected"),"The t-Test could prove that the sample mean was different to the population mean",IF(COUNTIF(D35:D37,"hypothesis null not rejected")=3,"The t-Test could Not prove that the sample mean was different to the population mean",""))

  10. #10
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: If Problems.....

    That could possibly be shortened to:

    =IF(COUNTIF(D35:D37,"<>")=3,"The t-Test could "&IF(COUNTIF(D35:D37,"*not*")=3,"Not ","")&"prove that the sample mean was different to the population mean","")

  11. #11
    Registered User
    Join Date
    04-09-2012
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2007
    Posts
    78

    Re: If Problems.....

    Macnautor,

    Try this code, it´s a little bit "Barbarian" but worked fine here:

    Please Login or Register  to view this content.
    Last edited by Pulsus; 05-28-2012 at 04:05 PM.

  12. #12
    Registered User
    Join Date
    05-28-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: If Problems.....

    Cutter, thanks for your help, however I want to use a macro to do it, I want to learn vba.

    pulsus, thanks for that, I will try that when I return to the computer.

  13. #13
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: If Problems.....

    Or maybe:
    Please Login or Register  to view this content.
    Ben Van Johnson

  14. #14
    Registered User
    Join Date
    05-28-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: If Problems.....

    ProtonLean

    Thanks but for some reason, you code did not fill with phrase b, but did with phrase a?

    Pulsus

    Your code was the same as ProtonLean, however, I understood yours a little more, (I think its because I am a little barbaric!) so I was able to edit it to produce the correct result, here is the code I used;

    Please Login or Register  to view this content.
    Thank you for your help, I would not have been able to finish this tonight if it wasn't for your input.

    Thanks again to all who had input to this thread.

  15. #15
    Registered User
    Join Date
    04-09-2012
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2007
    Posts
    78

    Re: If Problems.....

    Macnautor,

    Fine It works. Unfortunately sometimes we need to win by force...

+ 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