+ Reply to Thread
Results 1 to 5 of 5

Creating a function that is going wrong!

Hybrid View

  1. #1
    Registered User
    Join Date
    04-30-2013
    Location
    seoul
    MS-Off Ver
    Excel 2007
    Posts
    7

    Creating a function that is going wrong!

    Hi. I have created an excel quiz which asks 4 radio and one check box question. If a person gets A question right, it is linked to a box which becomes 1. A cell at the bottom adds these up and my task is to create a function that will turn the number that someone got right into the same number of stars. Here is my code below, first it comes up with #Value and then something about block ifs. Please tell me what I am doing wrong.

    Public Function Stars(number As Integer)

    If number = 0 Then Stars = ""
    End If
    If number = 1 Then Stars = "*"
    End If
    If number = 2 Then Stars = "**"
    End If
    If number = 3 Then Stars = "***"
    End If
    If number = 4 Then Stars = "****"
    End If
    If number = 5 Then Stars = "*****"
    End If


    End Function

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Creating a function that is going wrong!

    try
    Public Function Stars(number As Integer)
        If number > 0 Then Stars = String(number, "*")
    End Function
    Regards
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Registered User
    Join Date
    04-30-2013
    Location
    seoul
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Creating a function that is going wrong!

    It still seems to come up with #value, what does this actually mean and how can i solve it?

  4. #4
    Registered User
    Join Date
    04-30-2013
    Location
    seoul
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Creating a function that is going wrong!

    also, wouldn't your method show the number and then the stars, i need just the stars?

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,175

    Re: Creating a function that is going wrong!

    Put the function in a standard module.

    Then you can type, for example:

    =Stars(A1) ... if the number is in cell A1

    or

    Stars(3) for "***"


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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