Following on from an earlier equiry I have successfully managed to reduce over 2500 lines of code by about 90%, however, I believe that this can be further reduced by about another 90% as the code is repeated 8 times, once for every value in a ComboBox. The only difference to each "Block" is the target column range. I have 2 similar questions which I hope can be resolved without the need to re-write much of the code.
Here is a sample of the code showing two of the eight CBO Variable Values
Question 1 = Is there a way to merge the 2 items for Set vtd = Sheets("Variable Ticket Details")? I have tried a number of combinations, none of which were acceptable. The only differences are the target ComboBoxes and the source columns in the same Worksheet.
Question 2 = The only differences in each block are the Column Arrays and the data in cboTBallDrawNumber. The Values of this will be "Draw 1", "Draw 2" .....to "Draw 8". I feel sure that VBA must support the ability to include a variable that would look up the corresponding Arrays.
Please note that the row numbers remain the same for all "cboTBallDrawNumber" variables
As my code works and is much smaller than it was then I am happy for this to remain, But from a learning perspective, it would be useful to ask if this is possible before I start trying some ideas for how this might work.
Many thanks
Here is a sample of the code showing two of the eight CBO Variable Values
VBA Code:
Private Sub cmdThunderballCallDetails_Click()
Dim vCols As Variant
Dim lngRowLoop As Long
Dim lngCtrlLoop As Long
Dim tbCounter As Long
If cboTBallDrawNumber.Value = "Draw 1" Then
Set ctn = Sheets("Core Ticket Numbers")
tbCounter = 1
vCols = Array("B", "C", "D", "E", "F", "G")
For lngRowLoop = 44 To 56
For lngCtrlLoop = 0 To UBound(vCols)
Me.Controls("txtThunderballSelection" & tbCounter).Text = ctn.Range(vCols(lngCtrlLoop) & lngRowLoop).Value
tbCounter = tbCounter + 1
Next
Next
Set vtd = Sheets("Variable Ticket Details")
tbCounter = 1
vCols = Array("C")
For lngRowLoop = 46 To 58
For lngCtrlLoop = 0 To UBound(vCols)
Me.Controls("cboTballMethodLine" & tbCounter).Text = vtd.Range(vCols(lngCtrlLoop) & lngRowLoop).Value
tbCounter = tbCounter + 1
Next
Next
tbCounter = 1
vCols = Array("D")
For lngRowLoop = 46 To 58
For lngCtrlLoop = 0 To UBound(vCols)
Me.Controls("cboTballStatusLine" & tbCounter).Text = vtd.Range(vCols(lngCtrlLoop) & lngRowLoop).Value
tbCounter = tbCounter + 1
Next
Next
End If
If cboTBallDrawNumber.Value = "Draw 2" Then
Set ctn = Sheets("Core Ticket Numbers")
tbCounter = 1
vCols = Array("H", "I", "J", "K", "L", "M")
For lngRowLoop = 44 To 56
For lngCtrlLoop = 0 To UBound(vCols)
Me.Controls("txtThunderballSelection" & tbCounter).Text = ctn.Range(vCols(lngCtrlLoop) & lngRowLoop).Value
tbCounter = tbCounter + 1
Next
Next
Set vtd = Sheets("Variable Ticket Details")
tbCounter = 1
vCols = Array("E")
For lngRowLoop = 46 To 58
For lngCtrlLoop = 0 To UBound(vCols)
Me.Controls("cboTballMethodLine" & tbCounter).Text = vtd.Range(vCols(lngCtrlLoop) & lngRowLoop).Value
tbCounter = tbCounter + 1
Next
Next
tbCounter = 1
vCols = Array("F")
For lngRowLoop = 46 To 58
For lngCtrlLoop = 0 To UBound(vCols)
Me.Controls("cboTballStatusLine" & tbCounter).Text = vtd.Range(vCols(lngCtrlLoop) & lngRowLoop).Value
tbCounter = tbCounter + 1
Next
Next
End If
Question 1 = Is there a way to merge the 2 items for Set vtd = Sheets("Variable Ticket Details")? I have tried a number of combinations, none of which were acceptable. The only differences are the target ComboBoxes and the source columns in the same Worksheet.
Question 2 = The only differences in each block are the Column Arrays and the data in cboTBallDrawNumber. The Values of this will be "Draw 1", "Draw 2" .....to "Draw 8". I feel sure that VBA must support the ability to include a variable that would look up the corresponding Arrays.
Please note that the row numbers remain the same for all "cboTBallDrawNumber" variables
As my code works and is much smaller than it was then I am happy for this to remain, But from a learning perspective, it would be useful to ask if this is possible before I start trying some ideas for how this might work.
Many thanks