Hey Guys,
So I am basically done with the program. I've gotten the results I wanted mostly. My objective is to put down 20 cards and make sure there is no repeating Cards. This is my Code so far. All I'm having trouble with is that I cannot seem to figure out on how to make a filter for those values.
Any advice or examples would be greatly appreciated. Thanks in Advance!
Code:
Option Explicit
Dim MainFileNameLocation As String
Dim MainFileName As String
Sub Cardgame()
Dim CardRange As Range 'Ranges of cells that we will use to place the cards within
Dim Suits() As Variant 'Array to hold suit types
Dim CardCounter As Long
Dim Rsuite As Variant
Dim x As Integer
Dim Deck() As Variant
'(DEBUG CODE - BEGIN): Make sure to delete this an re-activate the MainFileName line when done
MainFileNameLocation = "C:\Users\sebastian.zdarowski\Desktop\VBA Files\Poker game_1_Copy"
MainFileName = "Poker game_1_copy"
Workbooks.Open (MainFileNameLocation)
'(DEBUG CODE - END)
'Loop through the range and place card values with selected range
x = 13
Worksheets("Cards").Activate
Restart:
For Each CardRange In Range("b2", Range("e6"))
If CardRange = "" Then
Rsuite = Int(Math.Rnd * 4) + 1
If Rsuite = 1 Then
Rsuite = Sheets("symbols").Range("b1").Value 'Hearts
ElseIf Rsuite = 2 Then
Rsuite = Sheets("symbols").Range("b2").Value 'Diamonds
ElseIf Rsuite = 3 Then
Rsuite = Sheets("symbols").Range("b3").Value 'Spades
Else
Rsuite = Sheets("symbols").Range("b4").Value 'Clubs
End If
CardRange = RandomCards(x) & Rsuite
CardCounter = CardCounter + 1
ReDim Preserve Deck(1 To CardCounter)
Deck(CardCounter) = CardRange
End If
Next CardRange
DidYouWin: MsgBox "Have you won? How well did you do?"
End Sub
Public Function RandomCards(x)
Dim Rcards As Variant
'Function used to get Random cards dealt to the deck
RandomCards = Int(Math.Rnd * x) + 1
If RandomCards = 11 Then
RandomCards = "J"
ElseIf RandomCards = 12 Then
RandomCards = "Q"
ElseIf RandomCards = 13 Then
RandomCards = "K"
ElseIf RandomCards = 1 Then
RandomCards = "A"
Else
Rcards = Rcards
End If
End Function
EXCEL 2013
Windows 7
So I am basically done with the program. I've gotten the results I wanted mostly. My objective is to put down 20 cards and make sure there is no repeating Cards. This is my Code so far. All I'm having trouble with is that I cannot seem to figure out on how to make a filter for those values.
Any advice or examples would be greatly appreciated. Thanks in Advance!
Code:
Option Explicit
Dim MainFileNameLocation As String
Dim MainFileName As String
Sub Cardgame()
Dim CardRange As Range 'Ranges of cells that we will use to place the cards within
Dim Suits() As Variant 'Array to hold suit types
Dim CardCounter As Long
Dim Rsuite As Variant
Dim x As Integer
Dim Deck() As Variant
'(DEBUG CODE - BEGIN): Make sure to delete this an re-activate the MainFileName line when done
MainFileNameLocation = "C:\Users\sebastian.zdarowski\Desktop\VBA Files\Poker game_1_Copy"
MainFileName = "Poker game_1_copy"
Workbooks.Open (MainFileNameLocation)
'(DEBUG CODE - END)
'Loop through the range and place card values with selected range
x = 13
Worksheets("Cards").Activate
Restart:
For Each CardRange In Range("b2", Range("e6"))
If CardRange = "" Then
Rsuite = Int(Math.Rnd * 4) + 1
If Rsuite = 1 Then
Rsuite = Sheets("symbols").Range("b1").Value 'Hearts
ElseIf Rsuite = 2 Then
Rsuite = Sheets("symbols").Range("b2").Value 'Diamonds
ElseIf Rsuite = 3 Then
Rsuite = Sheets("symbols").Range("b3").Value 'Spades
Else
Rsuite = Sheets("symbols").Range("b4").Value 'Clubs
End If
CardRange = RandomCards(x) & Rsuite
CardCounter = CardCounter + 1
ReDim Preserve Deck(1 To CardCounter)
Deck(CardCounter) = CardRange
End If
Next CardRange
DidYouWin: MsgBox "Have you won? How well did you do?"
End Sub
Public Function RandomCards(x)
Dim Rcards As Variant
'Function used to get Random cards dealt to the deck
RandomCards = Int(Math.Rnd * x) + 1
If RandomCards = 11 Then
RandomCards = "J"
ElseIf RandomCards = 12 Then
RandomCards = "Q"
ElseIf RandomCards = 13 Then
RandomCards = "K"
ElseIf RandomCards = 1 Then
RandomCards = "A"
Else
Rcards = Rcards
End If
End Function
EXCEL 2013
Windows 7