DixitCorvus
New Member
- Joined
- Jun 1, 2018
- Messages
- 3
I am trying to build a macro that does a couple different random selections. The first function would be to randomly select a name from a table on another tab; this portion is working perfectly fine. The second portion is a randomly generated Yes/No. Here's what I've got so far:
Sub NewCast()
Dim NPC_Row As Double
Dim NPC_Shapeshift As Double
Dim NPC_Shapeshift_Result As String
Randomize
NPC_Row = Int((Rnd() * (Sheets("NPCs").UsedRange.Rows.Count - 1)) + 1)
NPC_Name = Sheets("NPCs").Range("A" & NPC_Row)
Lastrow_NPC = Sheets("NPCs").Range("K1").Value
NPC_Shapeshift = Rnd()
If NPC_Shapeshift > 0.5 Then
NPC_Shapeshift_Result = "Yes"
Else
NPC_Shapeshift_Result = "No"
End If
Sheets("Cast").Range("A" & Lastrow_NPC).Value = NPC_Name
Sheets("Cast").Range("C" & Lastrow_NPC).Value = NPC_Shapeshift_Result
End Sub
Column A of the "Cast" Sheet is the Randomly selected name. Column C is the randomly selected Yes/No value.
LastRow_NPC determines the number of entries already on the "Cast" Sheet telling this macro where to enter the new entry.
Everything looks good to me, but I'm getting an "Application-defined or Object-defined Error" which seems to be associated with the last line:
Sheets("Cast").Range("C" & Lastrow_NPC).Value = NPC_Shapeshift_Result
Any ideas?
Sub NewCast()
Dim NPC_Row As Double
Dim NPC_Shapeshift As Double
Dim NPC_Shapeshift_Result As String
Randomize
NPC_Row = Int((Rnd() * (Sheets("NPCs").UsedRange.Rows.Count - 1)) + 1)
NPC_Name = Sheets("NPCs").Range("A" & NPC_Row)
Lastrow_NPC = Sheets("NPCs").Range("K1").Value
NPC_Shapeshift = Rnd()
If NPC_Shapeshift > 0.5 Then
NPC_Shapeshift_Result = "Yes"
Else
NPC_Shapeshift_Result = "No"
End If
Sheets("Cast").Range("A" & Lastrow_NPC).Value = NPC_Name
Sheets("Cast").Range("C" & Lastrow_NPC).Value = NPC_Shapeshift_Result
End Sub
Column A of the "Cast" Sheet is the Randomly selected name. Column C is the randomly selected Yes/No value.
LastRow_NPC determines the number of entries already on the "Cast" Sheet telling this macro where to enter the new entry.
Everything looks good to me, but I'm getting an "Application-defined or Object-defined Error" which seems to be associated with the last line:
Sheets("Cast").Range("C" & Lastrow_NPC).Value = NPC_Shapeshift_Result
Any ideas?