SunderlandUK
New Member
- Joined
- Mar 7, 2011
- Messages
- 12
Hi
I'm trying to use Excel as a cricket game and have found snippets of cricket related code on the internet and it seems to work. A random number is generated in cell C2 and is allocated to a batsman (bat number in cell M9). The corresponding numbers are entered in a table in a row next to their name. However, I would like to have this table in Sheet 2 - when I try and adapt the code, I get a "Object variable or With Block variable not set" error message for the code line c.value = Range("C2"). I don't know hoe to fix this.
Sub InsertScore()
currentbatrow = Range("M9")
If Range("C6") = 10 Then
Else
Set c = Range("E" & currentbatrow & ":" & "R" & currentbatrow).Find(what:="", LookIn:=xlValues, SearchOrder:=xlByRows)
If c Is Nothing Then
Range("M9").Value = Range("M9").Value + 1
currentbatrow = Range("M9")
Set c = Range("E" & currentbatrow & ":" & "R" & currentbatrow).Find(what:="", LookIn:=xlValues, SearchOrder:=xlByRows)
End If
c.Value = Range("C2")
If c.Value = "Bowled" Or c.Value = "Caught" Or c.Value = "LBW" Or c.Value = "Stumped" Then Range("M9").Value = Range("M9").Value + 1
c.Activate
End If
End Sub
I'm trying to use Excel as a cricket game and have found snippets of cricket related code on the internet and it seems to work. A random number is generated in cell C2 and is allocated to a batsman (bat number in cell M9). The corresponding numbers are entered in a table in a row next to their name. However, I would like to have this table in Sheet 2 - when I try and adapt the code, I get a "Object variable or With Block variable not set" error message for the code line c.value = Range("C2"). I don't know hoe to fix this.
Sub InsertScore()
currentbatrow = Range("M9")
If Range("C6") = 10 Then
Else
Set c = Range("E" & currentbatrow & ":" & "R" & currentbatrow).Find(what:="", LookIn:=xlValues, SearchOrder:=xlByRows)
If c Is Nothing Then
Range("M9").Value = Range("M9").Value + 1
currentbatrow = Range("M9")
Set c = Range("E" & currentbatrow & ":" & "R" & currentbatrow).Find(what:="", LookIn:=xlValues, SearchOrder:=xlByRows)
End If
c.Value = Range("C2")
If c.Value = "Bowled" Or c.Value = "Caught" Or c.Value = "LBW" Or c.Value = "Stumped" Then Range("M9").Value = Range("M9").Value + 1
c.Activate
End If
End Sub