Consulting

Results 1 to 3 of 3

Thread: VBA Case Statement verification; Homework

  1. #1
    VBA Student VBAX Regular
    Joined
    Mar 2008
    Posts
    20

    VBA Case Statement verification; Homework

    I was just wondering if i have followed the following criteria correctly
    1. Create a function GetProducerRow() which takes in one String input (give it any name following the conventions) and returns an Integer.
    2. Write a Select Case statement inside the function.
      • It should compare the input string with the various companies listed in the Voting tables in cells F5:F9.
      • The Case should not use hard coded values for the names of the companies but something like Range("F5").Value.
      • In each case, set the return value by assigning the appropriate row number. For example, the value assigned would be 5 for "The Hershey Company" store in F5.
      • Remember to write Case statement for each of the 5 producers.
      • Add the Case Else in-case none of the producers match the input and have the return value set to 0.
    Function GetProducerRow(strProducer As String) As Integer
    strProducer = Range("F5")
    Select Case strProducer
    
    Case Range("F5").Value
    Range("G5").Value = 5
    Case Range("F6").Value
    Range("G6").Value = 4
    Case Range("F7").Value
    Range("G7").Value = 3
    Case Range("F8").Value
    Range("G8").Value = 4
    Case Range("F9").Value
    Range("G9").Value = 3
    Case Else
    Range("G5") = 0
    
    End Select
    
    
    End Function

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Homework question
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Point 3 score is 0/5, as is your basic understanding of returning the value of the function. Read your course notes again, bearing in mind the first requirement of your question.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •