Mark or Gary I need some guidance with a VBA error 1004

Please post any questions regarding the program here.

Moderator: 2020vision

Mark or Gary I need some guidance with a VBA error 1004

Postby xraymitch » Thu Jan 24, 2019 5:46 pm

I posted this request for help a week ago and so far no one apart from me has viewed or commented but perhaps I didn't make myself clear.

I am Logging Current Prices into multiple sheets and Auto Selecting markets 15 minutes before the off. In addition, with my basic VBA skills, I am trying to record the distance and race duration times since the off.

As long as only one sheet is active everything works perfectly and the Range("W1:AH1") gets recorded to the sheet.

If for example, 2 or more markets are active as in say the 15:00 and 15:15, then at some point I get the error 1004 which freezes all markets from loading etc.

I have spent many hours trying to understand Methods, Properties Objects etc,and I am dismayed by my inability to grasp how to implement the code properly, I woud be obliged if you Mark, or Gary could at least give me a clue or point me in the right direction.

Here below is the link to my post of last Thusday:

viewtopic.php?f=5&t=10281#p52292

Many thanks,

xraymitch 8)
xraymitch
 
Posts: 410
Joined: Wed Jun 25, 2008 7:06 am
Location: UK

Re: Mark or Gary I need some guidance with a VBA error 1004

Postby Captain Sensible » Thu Jan 24, 2019 9:07 pm

Only had a quick look but is there any major reason why you're using .Select and .Activate to do simple copies? You can simply copy one range to another by using something like

Code: Select all
Range("W1:AH1").Value = Range("A1:L1").Value


It could be that as you're code is firing off the active focus is bouncing between sheets. It's generally considered good practice to fully reference your cells because if a sheet other than the one you're working on becomes active any changes would happen on the new sheet and previous objects/references may no longer be valid.

i.e

Code: Select all
Sheets("Sheet1").Range("C21").Value

or use

With Target.Parent


etc
User avatar
Captain Sensible
 
Posts: 2923
Joined: Sat Nov 19, 2005 2:29 pm

Re: Mark or Gary I need some guidance with a VBA error 1004

Postby Captain Sensible » Thu Jan 24, 2019 9:08 pm

There's also a Workbook.SheetChange Event you might want to consider using in ThisWorbook to save you duplicating the same code for each sheet.
User avatar
Captain Sensible
 
Posts: 2923
Joined: Sat Nov 19, 2005 2:29 pm

Re: Mark or Gary I need some guidance with a VBA error 1004

Postby xraymitch » Fri Jan 25, 2019 10:54 pm

Captain Sensible as always I just want to thank you

"Only had a quick look but is there any major reason why you're using .Select and .Activate to do simple copies? You can simply copy one range to another by using something like"

This is something I have discovered and wanted to use.

"It could be that as you're code is firing off the active focus is bouncing between sheets. It's generally considered good practice to fully reference your cells because if a sheet other than the one you're working on becomes active any changes would happen on the new sheet and previous objects/references may no longer be valid."

This is my thinking to.


I wanted to try finding a way of creating Range("AT43:BE43").Value = Range("W1:AH1").Value and tried experimenting with the following:

Dim RaceM5 As Range
Set RaceM5 = Range("W1:AH1").Value

Dim RecordM5 As Range
Set RecordM5 As Offset(Cells(1, 27), 23) this code would produce an error immediately in VBA

I tried experimenting with Ranges and my thinking here was that if at some point cell W1 was made the Active cell then the value contained in cell AA1 would give the offset row number and 23 would give the offset column number for the next record. Thus if AA1 contained 52, then RecordM5 would equate to the Range("AT53").

Because of the error in the above code I never progressed into working out how I could add the "BE43" part to the range but ultimately I wanted to wanted to be able to write RecordM5.Value = RaceM5.Value

I also tried writing as Worksheets("Sheet5").Range("AT43:BE43").Value = Worksheets("Sheet5").Range("W1:AH1").Value

To put in in simple terms all I want to do is copy the Range("W1:AH1") which contains the data for every race.
xraymitch
 
Posts: 410
Joined: Wed Jun 25, 2008 7:06 am
Location: UK

Re: Mark or Gary I need some guidance with a VBA error 1004

Postby Captain Sensible » Fri Jan 25, 2019 11:33 pm

xraymitch wrote:
To put in in simple terms all I want to do is copy the Range("W1:AH1") which contains the data for every race.


I'm still a bit confused as to why you're finding it a problem to copy Worksheets("Sheet5").Range("W1:AH1").Value into Worksheets("Sheet5").Range("AT43:BE43").Value with

Code: Select all
Worksheets("Sheet5").Range("AT43:BE43").Value =Worksheets("Sheet5").Range("W1:AH1").Value


If you wanted to retain the previous data when new races are added you could simply use something like below so you push the data in AT43:BE43 down 1 cell before adding new data, if you wanted to add new data into AT44:BE44 instead that's easy to do also using something like .End(xlUp).Row to find the last cell row with data

Code: Select all
With Target.Parent

.Range("AT43:BE43").Insert (xlShiftDown)
.Range("AT43:BE43").Value =.Range("W1:AH1").Value

End With
User avatar
Captain Sensible
 
Posts: 2923
Joined: Sat Nov 19, 2005 2:29 pm

Re: Mark or Gary I need some guidance with a VBA error 1004

Postby xraymitch » Sat Jan 26, 2019 6:39 am

Captain Sensible wrote:I'm still a bit confused as to why you're finding it a problem to copy Worksheets("Sheet5").Range("W1:AH1").Value into Worksheets("Sheet5").Range("AT43:BE43").Value with

Code: Select all
Worksheets("Sheet5").Range("AT43:BE43").Value =Worksheets("Sheet5").Range("W1:AH1").Value


To be honest I have forgotten why it was a problem - I had tried so many attempts that I got confused and reached burn out. I suspect the above code did work but I couldn't see how to increment the range which is why I was trying to work with the offset command.

Based on the examples you have shown me below and the new understanding you have given me I will start afresh and try to implement accordingly.

Captain Sensible wrote:If you wanted to retain the previous data when new races are added you could simply use something like below so you push the data in AT43:BE43 down 1 cell before adding new data, if you wanted to add new data into AT44:BE44 instead that's easy to do also using something like .End(xlUp).Row to find the last cell row with data



Code: Select all
With Target.Parent

.Range("AT43:BE43").Insert (xlShiftDown)
.Range("AT43:BE43").Value =.Range("W1:AH1").Value

End With

Captain Sensible wrote:There's also a Workbook.SheetChange Event you might want to consider using in ThisWorbook to save you duplicating the same code for each sheet.


A big THANKYOU Captain for taking the time to impart your knowledge and as I have said before in previous years - you are a STAR !!

8)
xraymitch
 
Posts: 410
Joined: Wed Jun 25, 2008 7:06 am
Location: UK


Return to Help

Who is online

Users browsing this forum: No registered users and 38 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.