|
-
Jun 10th, 2006, 03:21 AM
#1
Thread Starter
Addicted Member
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:
Function points()
Sheets("Sheet1").Select
position1 = Range("B6").Value
event1 = Range("B7").Value
' 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
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
-
Jun 10th, 2006, 10:36 AM
#2
Re: Comparisions based on value of 2 cells
If event1 comes out as a string:
VB Code:
If event1 <> "Relay" then
points = 5 - position1
Else
points = 10 - (position1*2)
End if
zaza
-
Jun 12th, 2006, 04:50 PM
#3
Thread Starter
Addicted Member
Re: Comparisions based on value of 2 cells
-
Jun 13th, 2006, 02:57 PM
#4
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 
-
Jun 14th, 2006, 01:40 PM
#5
Thread Starter
Addicted Member
Re: Comparisions based on value of 2 cells
VB Code:
Calculate
Sheets("Sheet1").Select
position1 = Range("B6").Value
event1 = Range("B7").Value
If event1 <> "Relay" Then
points = 5 - position1
Range("B8").Select
ActiveCell.FormulaR1C1 = "points"
Calculate
Else
points = 10 - (position1 * 2)
Range("B8").Select
ActiveCell.FormulaR1C1 = "points"
Calculate
End If
Calculate
NextRow = Worksheets("Sheet3").Range("B65536").End(xlUp).Row + 1
Worksheets("Sheet3").Cells(NextRow, 2).Resize(1, 7).Value = Array( _
Worksheets("Sheet1").Range("B2").Value, _
Worksheets("Sheet1").Range("B3").Value, _
Worksheets("Sheet1").Range("B4").Value, _
Worksheets("Sheet1").Range("B5").Value, _
Worksheets("Sheet1").Range("B6").Value, _
Worksheets("Sheet1").Range("B7").Value, _
Worksheets("Sheet1").Range("B8").Value)
Sheets("Sheet1").Select
Range("B2:B7").Select
Selection.ClearContents
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?
-
Jun 14th, 2006, 01:42 PM
#6
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 
-
Jun 17th, 2006, 12:27 PM
#7
Thread Starter
Addicted Member
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
-
Jun 19th, 2006, 12:15 PM
#8
Thread Starter
Addicted Member
Re: Comparisions based on value of 2 cells
-
Jun 22nd, 2006, 07:27 AM
#9
Thread Starter
Addicted Member
Re: Comparisions based on value of 2 cells
OK how can I find the sum of each team?
-
Jun 22nd, 2006, 09:38 AM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|