I ran the following subroutine and it resulted in a Run-time error "13", Type Mismatch. I highlighted the part of the code where the program stopped and gave me the message.
Might anyone have a thought on what the problem might be or something else I might be able to try?
In case you need to know, AO6:AO25 contains a set of numbers that may range from 1 - 30 and could hold anywhere from 5 to a max of 20 numbers. Also, A4:AH34 is a chart that contains another set of names and numbers that is ultimately used in another part of a larger program. All I'm trying to do here is to change numbers in Row 3 (E3:AH3) and Column A (A6:A34) to 1 if a player's number is found in the chart located in AO6:AO25. Then sort it from top to bottom and left to right in order to pull all the active players together.
Putting all the details aside, I'm really just trying to figure out why I'm getting the Run-time error "13" on the line of code below. And I'm at a total loss of what might be the problem.
I appreciate anyone willing to look at this and provide some guidance.
Sub PreComboSort()
' ******************************
' * This is to Sort numbers based on who's been chosen to play
' ******************************
Dim Player As Long
Dim LastRowa As Long
Dim LastRowb As Long
Dim A As Long
Dim b As Long
Dim i As Long
Dim ii As Long
LastRowa = Sheets("CommonData2").Range("AO" & Rows.Count).End(xlUp).Row
LastRowb = Sheets("CommonData2").Range("C" & Rows.Count).End(xlUp).Row
' In the respective rows marked players who will be playing with the number 1
For i = 6 To LastRowa
Player = Sheets("CommonData2").Range("AO" & i).Value '<===== Run-time error '13'
For ii = 6 To LastRowb
If Sheets("CommonData2").Range("B" & ii).Value = Player Then
Sheets("CommonData2").Range("A" & ii).Value = "1"
End If
Next ii
Next i
Dim PlayerR As Long
Dim LastRow As Long
Dim ir As Long
Dim counter As Integer
LastRow = Sheets("CommonData2").Range("AO" & Rows.Count).End(xlUp).Row
' In the respective columns, marked players who will be playing with the number 1
For ir = 6 To LastRow
PlayerR = Sheets("CommonData2").Range("AO" & ir).Value
For counter = 5 To 34
If Worksheets("CommonData2").Cells(4, counter).Value = PlayerR Then
Worksheets("CommonData2").Cells(3, counter).Value = 1
End If
Next counter
Next
' Following code sorts chart from top to bottom
Dim rng2 As Range
Set ws2 = Worksheets("CommonData2")
Set rng2 = ws2.Range("A6:AL34")
ws2.Sort.SortFields.Clear
With rng2
.Sort Key1:=ws2.Range("A6"), Order1:=xlAscending, _
Header:=xlNo
End With
' Following code sorts chart from left to right
ws2.Sort.SortFields.Clear
ws2.Range("E3:AH34").Sort Key1:=ws2.Range("E3:AH34"), Order1:=xlAscending, Orientation:=xlLeftToRight
End Sub
Might anyone have a thought on what the problem might be or something else I might be able to try?
In case you need to know, AO6:AO25 contains a set of numbers that may range from 1 - 30 and could hold anywhere from 5 to a max of 20 numbers. Also, A4:AH34 is a chart that contains another set of names and numbers that is ultimately used in another part of a larger program. All I'm trying to do here is to change numbers in Row 3 (E3:AH3) and Column A (A6:A34) to 1 if a player's number is found in the chart located in AO6:AO25. Then sort it from top to bottom and left to right in order to pull all the active players together.
Putting all the details aside, I'm really just trying to figure out why I'm getting the Run-time error "13" on the line of code below. And I'm at a total loss of what might be the problem.
I appreciate anyone willing to look at this and provide some guidance.
Sub PreComboSort()
' ******************************
' * This is to Sort numbers based on who's been chosen to play
' ******************************
Dim Player As Long
Dim LastRowa As Long
Dim LastRowb As Long
Dim A As Long
Dim b As Long
Dim i As Long
Dim ii As Long
LastRowa = Sheets("CommonData2").Range("AO" & Rows.Count).End(xlUp).Row
LastRowb = Sheets("CommonData2").Range("C" & Rows.Count).End(xlUp).Row
' In the respective rows marked players who will be playing with the number 1
For i = 6 To LastRowa
Player = Sheets("CommonData2").Range("AO" & i).Value '<===== Run-time error '13'
For ii = 6 To LastRowb
If Sheets("CommonData2").Range("B" & ii).Value = Player Then
Sheets("CommonData2").Range("A" & ii).Value = "1"
End If
Next ii
Next i
Dim PlayerR As Long
Dim LastRow As Long
Dim ir As Long
Dim counter As Integer
LastRow = Sheets("CommonData2").Range("AO" & Rows.Count).End(xlUp).Row
' In the respective columns, marked players who will be playing with the number 1
For ir = 6 To LastRow
PlayerR = Sheets("CommonData2").Range("AO" & ir).Value
For counter = 5 To 34
If Worksheets("CommonData2").Cells(4, counter).Value = PlayerR Then
Worksheets("CommonData2").Cells(3, counter).Value = 1
End If
Next counter
Next
' Following code sorts chart from top to bottom
Dim rng2 As Range
Set ws2 = Worksheets("CommonData2")
Set rng2 = ws2.Range("A6:AL34")
ws2.Sort.SortFields.Clear
With rng2
.Sort Key1:=ws2.Range("A6"), Order1:=xlAscending, _
Header:=xlNo
End With
' Following code sorts chart from left to right
ws2.Sort.SortFields.Clear
ws2.Range("E3:AH34").Sort Key1:=ws2.Range("E3:AH34"), Order1:=xlAscending, Orientation:=xlLeftToRight
End Sub