Help With Copying a column

Please post any questions regarding the program here.

Moderator: 2020vision

Help With Copying a column

Postby Kentucky » Tue Aug 24, 2010 7:32 am

Hi Guys

I want to copy the values in 1 column to another and then clear it when the next race is selected

What I need is

When Cell AA1=1 (this cell is a coundown timer

Copy the Values from AA5:AA34 to AN5:AN35 (I only want to copy the values from AA5:AA34 not the formulas)

AA5:AA34 is a calculation that will change as the race progresses
I want to know what it is at the start of the Race this would be copied to AN5:AN34 so that I can compare the 2 figures during the race

When the next race is selected I then want to CLEAR the values in AN5:AN34 and repeat the process for the next race

Any Help would be appreciated

Thanks

Ken
Kentucky
 
Posts: 22
Joined: Tue Aug 04, 2009 8:01 am

Postby osknows » Tue Aug 24, 2010 10:44 am

This should work. Rather than CLEAR the range when the race changes it clears the range when coundown timer is greater than 1

Code: Select all
Private Sub Worksheet_change(ByVal Target As Range)
If Target.Columns.Count <> 16 Then Exit Sub
Application.EnableEvents = False
   
   
With ThisWorkbook.Sheets(Target.Worksheet.Name)

If .Range("AA1") = 1 Then

.Range("AN5:AN35").Value = .Range("AA5:AA35").Value

ElseIf .Range("AA1") > 1 Then
.Range("AN5:AN35").ClearContents

End If
End With
   
Application.EnableEvents = True
End Sub
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby Kentucky » Tue Aug 24, 2010 6:47 pm

Thanks Osknows just what I was looking for
Kentucky
 
Posts: 22
Joined: Tue Aug 04, 2009 8:01 am

Postby Shaun » Wed Aug 25, 2010 1:37 pm

I thought i would use this code but having trouble getting it to work, the idea is when cell S2 is populated with a 1 the macro will record the cells then paste them on another sheet, each time it pastes the infor it will past it under the old info but it won't fire, i have this in the control sheet at the moment.

Private Sub Worksheet_change(ByVal Target As Range)
If Target.Columns.Count <> 16 Then Exit Sub
Application.EnableEvents = False


With ThisWorkbook.Sheets(Target.Worksheet.Name)

If Range("S2") = 1 Then
Range("A8:P55").Select
Selection.Copy
Sheets("Record").Range("A1").Select
Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial (xlPasteValues)
Sheets("Control").Range("A1").Select
Application.CutCopyMode = False
End If
End With
Application.EnableEvents = True
End Sub
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Postby osknows » Wed Aug 25, 2010 2:12 pm

It's likely your control sheet doesn't have any cells being changed so the worksheet_change event won't fire. Change it to a a worksheet_calculate event so it fires when the control sheet calcs update.

Better still move the code to the sheet event linked to BA and paste to a new sheet on each refresh
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby Shaun » Wed Aug 25, 2010 2:39 pm

Cell S2 has a formula in it that is 0 untill a specific time then changes to 1 at that time all bets are made, i just want to record this information when the bets are made.
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Postby osknows » Wed Aug 25, 2010 3:04 pm

Code: Select all
Private Sub Worksheet_calculate()
Dim ba_array() As Variant

Application.EnableEvents = False

If ThisWorkbook.Sheets("Control").Range("S2").Value = 1 Then
ba_array = ThisWorkbook.Sheets("Control").Range("A8:P55").Value

With ThisWorkbook.Sheets("Record")
.Range(.Range("A" & .Range("A" & Rows.Count).End(xlUp).Row).Offset(1, 0), _
.Range("A" & .Range("A" & Rows.Count).End(xlUp).Row).Offset(UBound(ba_array, 1) - 1, _
UBound(ba_array, 2) - 1)).Value = ba_array
End With

End If

Application.EnableEvents = True
End Sub
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby Shaun » Wed Aug 25, 2010 3:22 pm

Why do macros have to be so difficult still no good, will run if i do it manually but not on it's own
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Postby Shaun » Wed Aug 25, 2010 3:26 pm

Sorry seans to work but is not putting text under neath but over the top.
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Postby osknows » Wed Aug 25, 2010 8:47 pm

Shaun wrote:Cell S2 has a formula in it that is 0 untill a specific time then changes to 1 at that time all bets are made, i just want to record this information when the bets are made.


If you place the code in the same sheet object as the S2 cell containing the formula the worksheet_calculate will fire after the worksheet is recalculated, for the worksheet object.
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby Shaun » Thu Aug 26, 2010 12:53 am

This code works now except it fires twice, once when the cell changes to 1 then again when it changes back, unless you have a fix for that i can live with it.

Code: Select all
Private Sub Worksheet_calculate()
Static MyMarket As Variant
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
If [S1].Value = MyMarket Then
GoTo Xit
Else
MyMarket = [S1].Value

ba_array = ThisWorkbook.Sheets("Control").Range("A8:P55").Value

With ThisWorkbook.Sheets("Recorded")

Dim LastRow As Long
LastRow = .Range("A65536").End(xlUp).Row

.Range(.Cells(LastRow + 1, 1), .Cells(LastRow + 1 + UBound(ba_array, 1), 1 + UBound(ba_array, 2))).Value = ba_array

End With

End If
Xit:
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub

Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Postby osknows » Thu Aug 26, 2010 12:33 pm

It's because you've removed the IF statement testing if S1 = 1

"If ThisWorkbook.Sheets("Control").Range("S2").Value = 1 Then"
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am


Return to Help

Who is online

Users browsing this forum: No registered users and 31 guests

Sports betting software from Gruss Software


The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.

Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.

Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.

He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.

We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.