Ladies and Gentlemen:
To say the least, I am completely baffled by what I am observing when a section of my Macro is implemented within my worksheet. To add to the confusion, the macro seems to work 50% of the time. If you will allow me, I'll share that portion of the code which is causing the problem and if someone would be so kind as to find the error or suggest a protentional solution or test... I would be so grateful.
First, you can see that I have made a couple attempts at debugging this myself and this is how I've been able to focus in on this particular piece of code.
Something seems to be causing the SORT to randomly lose all the values and I don't understand how or why. If anyone has any thoughts or suggestions, I would greatly appreciate it. Thank you for any assistance or guidance you can provide.
MsgBox "After Subroutine PlayerCombo - in Court2: " & Sheets("Courts2").Range("C7").Value & Sheets("Courts2").Range("D7").Value & Sheets("Courts2").Range("E7").Value & Sheets("Courts2").Range("F7").Value
'##################################################################################################################################
'# Once all player combos are written to Courts2, an additional column (Q) filled with calculations must be sorted decending order
'# with column P being the secondary sort
'##################################################################################################################################
ActiveWorkbook.Worksheets(wsName).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(wsName).Sort.SortFields.Add Key:=Range( _
"Q7:Q1826"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets(wsName).Sort.SortFields.Add Key:=Range( _
"P7:P1826"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets(wsName).Sort
.SetRange Range("C7:Q1826")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
MsgBox "After Worksheet Sort - in Court2: " & Sheets("Courts2").Range("C7").Value & Sheets("Courts2").Range("D7").Value & Sheets("Courts2").Range("E7").Value & Sheets("Courts2").Range("F7").Value
To say the least, I am completely baffled by what I am observing when a section of my Macro is implemented within my worksheet. To add to the confusion, the macro seems to work 50% of the time. If you will allow me, I'll share that portion of the code which is causing the problem and if someone would be so kind as to find the error or suggest a protentional solution or test... I would be so grateful.
First, you can see that I have made a couple attempts at debugging this myself and this is how I've been able to focus in on this particular piece of code.
- The first "MsgBox" comes right after a subroutine called PlayerCombo completes. I wanted to see if this subroutine writes the computed values to the spreadsheet at the desired locations
- Answer: YES... every time the subroutine is run, the computed values are written to the desired locations
- The second "MsgBox" comes right after the Sort code completes. Here, I simply wanted to verify that after the conclusion of the Sort, the desired location still has values.
- Answer: This is where I am baffled. The results are inconsistent. Sometimes values will be displayed after the SORT and other times NO values will be displayed.
Something seems to be causing the SORT to randomly lose all the values and I don't understand how or why. If anyone has any thoughts or suggestions, I would greatly appreciate it. Thank you for any assistance or guidance you can provide.
MsgBox "After Subroutine PlayerCombo - in Court2: " & Sheets("Courts2").Range("C7").Value & Sheets("Courts2").Range("D7").Value & Sheets("Courts2").Range("E7").Value & Sheets("Courts2").Range("F7").Value
'##################################################################################################################################
'# Once all player combos are written to Courts2, an additional column (Q) filled with calculations must be sorted decending order
'# with column P being the secondary sort
'##################################################################################################################################
ActiveWorkbook.Worksheets(wsName).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(wsName).Sort.SortFields.Add Key:=Range( _
"Q7:Q1826"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets(wsName).Sort.SortFields.Add Key:=Range( _
"P7:P1826"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets(wsName).Sort
.SetRange Range("C7:Q1826")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
MsgBox "After Worksheet Sort - in Court2: " & Sheets("Courts2").Range("C7").Value & Sheets("Courts2").Range("D7").Value & Sheets("Courts2").Range("E7").Value & Sheets("Courts2").Range("F7").Value