This code is defining a function that checks if a Sheet exists and returns a boolean value. The Sub is attempting to activate a workbook. It then checks a sheet (DataEntry) and iterates through the rows and checks if the teamname is already a sheet and if it isn't create a new sheet of that name and paste the data into that sheet. If the sheet does exist then it copies it into the existing sheet. Then it adds 1 to the match number so that when it goes to paste again as that determines what row it pastes the data in. But when I attempt to run it via a button on the sheet it gives me the byref argument type mismatch error.
Any thoughts on what might be wrong?
Function shtexists(shtname As Worksheet) As Boolean
Dim sht As Worksheet
Set sht = Sheets(shtname)
On Error GoTo 0
SheetExists = Not sht Is Nothing
End Function
Sub AddData()
Workbooks("ScoutingDatabseMaster.xlsm").Activate
Dim teamname As String
Dim countery As Integer
Dim matchnumber As Integer
matchnumber = 1
countery = 4
teamname = Range("B4", "B" & countery)
For countery = 4 To 9
If shtexists(teamname) Then
Worksheets("DataEntry").Range("C" & countery, "M" & countery).Copy
Worksheets(teamname).Range("A" & matchnumber).Paste
If teamname = "" Then
MsgBox ("You forgot to Enter a Team Number!")
Else
Sheets.Add.Name = teamname
End If
Next countery
matchnnumber = matchnumber + 1
countery = 4
End Sub