I'm a beginner working with VBA. I first used the "record a new macro" function in Excel to create my first set of Macro's. I progressed to the point of looking for snippets of code on the internet to accomplish specific tasks that needed to be done. However, I am very aware that my coding is very inefficient and I have been trying to identify ways to make improvements but I have been having difficulties applying my findings to my specific coding.
I am submitting some actual code here with the hopes that someone would be able to make it more efficient for me. In doing so, I would try to read up and understand WHY it is more efficient and then try to carry that logic forward to other areas within my program. If anyone is willing to help out with this endeavor, it would be greatly appreciated. Here is a snippet of my code.
I am submitting some actual code here with the hopes that someone would be able to make it more efficient for me. In doing so, I would try to read up and understand WHY it is more efficient and then try to carry that logic forward to other areas within my program. If anyone is willing to help out with this endeavor, it would be greatly appreciated. Here is a snippet of my code.
This will represent only the initialization steps in my program and leads to more coding which is where I'm probably losing all my time but I think it is important to start off with correct/efficient coding. Thanks for any help and guidance anyone can provide.
Code:
' Initialize all players that have been identified for tennis matches.
' First select and copy players (values) that have been identified available
' from worksheet TeamSelection AG45:AG60 and paste them to worksheet
' TeamSelectin A8 (transposed)
Sheets("TeamSelection").Select
Range("AG45:AG60").Select
Selection.Copy
Range("A8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
' From Chart 10:
' Take original sorted sixteen players and place them (transposed) into AK24:AZ24
' This will initiate the process of identifying which 4 players have been selected
' to play and which players remain available to play on either TEAM # 2 or beyond
'
Range("AK24").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
' Sort CHART 15 (Worksheet TeamSelection AG45:AY60) on column "CB" (Low-High) in order to
' prepare for future LOOKUPS which requires player numbers to be in ALPHA or NUMERIC order
Range("AG45:AY60").Select
ActiveWorkbook.Worksheets("TEAMSELECTION").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("TEAMSELECTION").Sort.SortFields.Add Key:=Range( _
"AG45:AG60"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("TEAMSELECTION").Sort
.SetRange Range("AG45:AY60")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'
' DETERMINE TEAM # 1
' Takes 1820 combination (i.e., =COMBIN(16,4)) of potential teams and copies values to
' columns G - J
'
Range("C7:F1826").Select
Selection.Copy
Range("G7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
' Sort G7:S1826 by Column's K (Ascending), S (Descending) and R (Ascending)
' Purpose is to place all potential team options on top and all invalid team options at bottom
'
Range("G7:S1826").Select
ActiveWorkbook.Worksheets("TeamSelection").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("TeamSelection").Sort.SortFields.Add Key:=Range( _
"K7:K1826"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("TeamSelection").Sort.SortFields.Add Key:=Range( _
"R7:R1826"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("TeamSelection").Sort
.SetRange Range("G7:S1826")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Last edited by a moderator: