Good Luck, Omega 71 !
To help with the final stages, study these screenshots first. At the end of this process you should have a totalof 16 named ranges!
http://www.mediafire.com/download/1282ko1gq58lg6s/Project6_7(2).rar
Ok, this is the last instalment of this project. In this part on Sheet2 we will make a section of spreadsheet to allow input of 2 ball numbers, the first ocurring A and the ball that follows it, B and a button that runs a search for the draw numbers when B followed A at the current sheet 1 settings.
This facility needs
4 new named ranges:-
Click on cell K105, Name it
firstno. Give it a border and a background colour, as its an input cell.
click on cell P105, Name it
following_no. Give it a border and a background colour, as its an input cell.
click on cell O108 Name it draws.
Enter text "Draws" as it is a column header..
The output range is in fact 2 cols wide, so I
merged cells O109109 using the merge and centre button, then used format painter to copy this double width merged cell down to cell
O178.
To name the range Select range
O108178 Name it
drawsrange. Put a black box border around it.
'.....................End of named ranges
To create a kind of control panel look, I added some text and formatting ..
In cell
H105, I entered text "
Find when", also put a label below each of the input cells K105,P105 ..
B............
A respectively.
I
Merged cells K103104 and entered large text "
Enter Numbers", added a couple of down arrows to point to the input boxes.
M105 contains
text "followed" ,
Cell
Q105 contains a
formula =OFFSET(readout,firstno,following_no-1)
Cell
R105 contains a
formula =CONCATENATE(" times Over ",drawsback," draws in next but ",next_but," draw")
In cell
W108 I entered a checksum formula
=COUNTIF(drawsrange,">0")
I
merged T108:V108 and entered a
text label "
checksum"
Now to pull all this together in a logical way is down to formatting and borders as shown in the screenshot.
Note Q103:Z104 is where the macro button will go.
''.......................................................................
Next you need a couple of macros and a button.
Its best if you stay on the same module as the other main macros , at the very top of the module it will say
Option Explicit. underneath you need to add this line..
Dim drawnumbers(400) As Integer
it will now read:-
Option Explicit
Dim drawnumbers(400) As Integer
'thats the editing done here
then scroll to the bottom of the
module to the next available free space and paste in these macros..
Sub Find_drawnumbers() 'corresponding to (hand) input values on sheet 2
Dim i, d, q, nextbut, firstnum, followno, column, count As Integer
For i = 1 To 400 'clear draws array ' holds list of draws N followed that number
drawnumbers(i) = 0
Next
count = 0
nextbut = Range("next_but").Value
followno = Range("firstno").Value
firstnum = Range("following_no").Value
d = Range("maxdraw").Value 'how many draws
q = Range("drawsback").Value - 1 'how far are you looking back
Application.ScreenUpdating = False
Sheets("sheet1").Select
Range("start").Offset(q - d, 0).Select 'Select 'Range("start").Select
For column = 0 To 5 'first column is 0 with x direction offset of 0
Selection.Offset(0, 1).Select 'move to right one
For i = 0 To q + 1
If Selection.Offset(-i, 0).Value = firstnum Then 'we are dealing with our first number and the numbers following it
If Selection.Offset(-i - 1 - nextbut, 0 - column) = followno Then
count = count + 1
drawnumbers(count) = Selection.Offset(-i - nextbut, 0 - column - 1).Value
End If
If Selection.Offset(-i - 1 - nextbut, 1 - column) = followno Then
count = count + 1
drawnumbers(count) = Selection.Offset(-i - nextbut, 0 - column - 1).Value
End If
If Selection.Offset(-i - 1 - nextbut, 2 - column) = followno Then
count = count + 1
drawnumbers(count) = Selection.Offset(-i - nextbut, 0 - column - 1).Value
End If
If Selection.Offset(-i - 1 - nextbut, 3 - column) = followno Then
count = count + 1
drawnumbers(count) = Selection.Offset(-i - nextbut, 0 - column - 1).Value
End If
If Selection.Offset(-i - 1 - nextbut, 4 - column) = followno Then
count = count + 1
drawnumbers(count) = Selection.Offset(-i - nextbut, 0 - column - 1).Value
End If
If Selection.Offset(-i - 1 - nextbut, 5 - column) = followno Then
count = count + 1
drawnumbers(count) = Selection.Offset(-i, 0 - column - 1).Value
End If
End If
Next i
Next column
Call readoutdraws(count)
Application.ScreenUpdating = True
End Sub
Sub readoutdraws(c As Integer) ' when A followed B.. result on sheet 2
Dim i As Integer
Sheets("Sheet2").Select
Range("drawsrange").Select
Selection.ClearContents
Range("draws").Select
Selection.Value = "Draws"
For i = 1 To c
Selection.Offset(i, 0).Value = drawnumbers(i) + 1 'the follower is in the next draw to the firstno
Next
Range("drawsrange").Select
Selection.Sort Key1:=Range("draws"), Order1:=xlDescending, Header:=xlYes _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("draws").Select
End Sub
' end of the new macros
There is a minor modification to the existing readout() macro too ..
At the very top, it begins:--
Sub readout()
Dim j As Integer
Sheets("sheet2").Select
Range("readout").Select
after the row Sheets("sheet2").Select ......... add these 2 rows
Range("drawsrange").Select
Selection.ClearContents
The new version now reads at the top...
Sub readout()
Dim j As Integer
Sheets("Sheet2").Select
Range("drawsrange").Select
Selection.ClearContents
Range("readout").Select
'----------------------------------- edit complete
Now to drive these macros:-
I created a forms button and shaped it to fit over
Q103:Z104, edited the button text to read "Find the draw numbers when B followed A" and assigned the macro (right click)
"find_drawnumbers" to it.
Ensure you have (within range) sensible ball number values entered into cells
K105,P105 that you wish to know the data for.This button should now extract the relevant draw numbers for the parameters you set before running the main macro on sheet1, and tell you when ball B followed Ball A.
The screenshot also shows something I just added, a column working out the "following skip" between these draws. You can add this if you wish with formula in cell Q109 =O109-O110 and copy this down the column.
----------------------------------------------------------------------------------------------------------------------------------------------------
To Add a variable number of new draws :- Requires the existing button on
sheet1 changing in size and shape to cover cells
A2:C3 and the text editing to read "
Add New Draw(s)". Cell A1 is a label containing
text "set how many" you may need to widen column A to 82 pixels and set a smaller font to fit it in.
Cell
B1 becomes new
named range called "
howmany", place a black box border around
B1 and highlight the cell background as its an input cell.
Enter number
1 into cell
B1, this is the default value ( of how many draws to add) that the macro will assume unless you change this value.
Now for the Macro:-
On the
same module as the newdraw macro (you need to keep this as it is still used)
Add this new macro:-
Sub EnterMultipleNewDraws()
Dim i, number As Integer
number = Range("howmany").Value
For i = 1 To number
NewDraw
Next
Range("howmany").Value = 1
End Sub
Thats the modification completed, it will now add as many draws as you like....
'.................................................................
If you wish to add a spinner to change the value in cell
J2 (note you can still type in values as well). then ..
.
on the
Developer tab>
Insert> choose
spin button (active X control) from the menu
draw out the spin control taller than its width, so arrow up and arrow down is what you see. Right click on it, choose
properties and select the
Alphabetic tab.
Click on
Linked cell and in the box to its right type in
J2. Make sure you are still clicked on the spinner and in its properties, Click on
Max and
choose what you think the maximum value should go to , say 10000 and enter it.
Be aware that whilst properties box is showing, wherever you click your mouse outside this box becomes the object whose properties you are
looking at. It is easy to click on the spreadsheet and not realise you are now looking at its properties - not the spinners ..watch out for that.
close the properties box.
Fine tune the shape and location of the spinner so its adjacent to the cell
J2. Note whilst doing this
you are in Design mode. This will prevent the spinner from working until you click on the design mode icon to
turn it off. Now test the spinner !
If you managed that OK, repeat the excercise but this time link it to cell M1, place the new spinner near cell M1, you may need to adjust row 1height to fit it in comfortably.
Thats all folks. Enjoy !
I'm going for a lie down ...