Results 1 to 10 of 10

Thread: Comparisions based on value of 2 cells

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    163

    Comparisions based on value of 2 cells

    I am creating a little sports day program in excel.

    I am trying to calculate the points based on event and postion.

    I have this at the moment for the points function:

    VB Code:
    1. Function points()
    2. Sheets("Sheet1").Select
    3. position1 = Range("B6").Value
    4. event1 = Range("B7").Value
    5.  
    6. ' if event not relay and position is 1st make points = 4
    7. ' if event not relay and position is 2nd make points = 3
    8. ' if event not relay and position is 3rd make points = 2
    9. ' if event not relay and position is 4th make points = 1
    10.  
    11. ' if event is relay and position is 1st make points = 8
    12. ' if event is relay and position is 2nd make points = 6
    13. ' if event is relay and position is 3rd make points = 4
    14. ' if event is relay and position is 4th make points = 2
    15.  
    16.  
    17. End Function

    How can I do these comparsions:

    if event not relay and position is 1st make points = 4
    if event not relay and position is 2nd make points = 3
    if event not relay and position is 3rd make points = 2
    if event not relay and position is 4th make points = 1

    if event is relay and position is 1st make points = 8
    if event is relay and position is 2nd make points = 6
    if event is relay and position is 3rd make points = 4
    if event is relay and position is 4th make points = 2


    Thank you

  2. #2
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Comparisions based on value of 2 cells

    If event1 comes out as a string:

    VB Code:
    1. If event1 <> "Relay" then
    2. points = 5 - position1
    3. Else
    4. points = 10 - (position1*2)
    5. End if


    zaza
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    163

    Re: Comparisions based on value of 2 cells

    so what does <> mean?

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Comparisions based on value of 2 cells

    "Not Equal To"

    i.e. <> <> =
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    163

    Re: Comparisions based on value of 2 cells

    VB Code:
    1. Calculate
    2.  
    3. Sheets("Sheet1").Select
    4. position1 = Range("B6").Value
    5. event1 = Range("B7").Value
    6.  
    7.  
    8. If event1 <> "Relay" Then
    9. points = 5 - position1
    10. Range("B8").Select
    11. ActiveCell.FormulaR1C1 = "points"
    12. Calculate
    13. Else
    14. points = 10 - (position1 * 2)
    15. Range("B8").Select
    16. ActiveCell.FormulaR1C1 = "points"
    17. Calculate
    18. End If
    19.  
    20.  
    21.  
    22. Calculate
    23.  
    24.     NextRow = Worksheets("Sheet3").Range("B65536").End(xlUp).Row + 1
    25.     Worksheets("Sheet3").Cells(NextRow, 2).Resize(1, 7).Value = Array( _
    26.         Worksheets("Sheet1").Range("B2").Value, _
    27.         Worksheets("Sheet1").Range("B3").Value, _
    28.         Worksheets("Sheet1").Range("B4").Value, _
    29.         Worksheets("Sheet1").Range("B5").Value, _
    30.         Worksheets("Sheet1").Range("B6").Value, _
    31.         Worksheets("Sheet1").Range("B7").Value, _
    32.         Worksheets("Sheet1").Range("B8").Value)
    33.        
    34.        
    35.         Sheets("Sheet1").Select
    36.         Range("B2:B7").Select
    37.         Selection.ClearContents
    38.         Range("B2").Select

    Is what I have at the moment but I get an error "13" Type Mismatch error.

    What could be causing that?

    Can you help me?

  6. #6
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Comparisions based on value of 2 cells

    What line is giving you the error?
    Also, have you declared your variables? If so, what are the dattypes?
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    163

    Re: Comparisions based on value of 2 cells

    Thank you for all your help

    I have one last part of this project that I need help with.

    Have a look at the following image:



    How can I find the total points for each team i.e. chatsworth,melbourne, Gilbert and Hurst and put them in a leaderboard on a VBA form in decending order?

    Thank you in advance

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    163

    Re: Comparisions based on value of 2 cells

    Is it possible?

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    163

    Re: Comparisions based on value of 2 cells

    OK how can I find the sum of each team?

  10. #10
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Comparisions based on value of 2 cells

    Try using the Excel function SUMIF.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

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



Click Here to Expand Forum to Full Width