2 different excel workbooks

Please post any questions regarding the program here.

Moderator: 2020vision

2 different excel workbooks

Postby Shaun » Wed May 24, 2017 3:44 pm

I am trying to connect 2 different excel workbooks to 2 different tabs but and getting errors in VBA when the code executes, here are the macros, how do i get these to not cause an error.

Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count <> 16 Then Exit Sub
Application.EnableEvents = False
With ThisWorkbook
If .Sheets("Data").Range("T2").Value <> 1 Then
   .Sheets("Data").Range("T3").Value = 0
End If
If .Sheets("Data").Range("T2").Value = 1 And .Sheets("Data").Range("T3").Value <> 1 Then
   .Sheets("Results").Range("P" & Rows.Count).End(xlUp).Offset(1, 0).Resize(1, 4).Value = Sheets("Trading").Range("R9:U9").Value
   .Sheets("Data").Range("T3").Value = 1
End If
End With
Application.EnableEvents = True
End Sub




Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count <> 16 Then Exit Sub
Application.EnableEvents = False
With ThisWorkbook
If .Sheets("Race1").Range("T2").Value <> 1 Then
   .Sheets("Race1").Range("T3").Value = 0
End If
If .Sheets("Race1").Range("T2").Value = 1 And .Sheets("Race1").Range("T3").Value <> 1 Then
   .Sheets("Results1").Range("H" & Rows.Count).End(xlUp).Offset(1, 0).Resize(1, 4).Value = Sheets("Control").Range("P9:S9").Value
   .Sheets("Race1").Range("T3").Value = 1
End If
End With
Application.EnableEvents = True
End Sub
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Re: 2 different excel workbooks

Postby alrodopial » Wed May 24, 2017 7:49 pm

I don't see the dot at
Code: Select all
= Sheets("Trading").Range("R9:U9").Value


is it required?
alrodopial
 
Posts: 1384
Joined: Wed Dec 06, 2006 9:59 pm

Re: 2 different excel workbooks

Postby Shaun » Wed May 24, 2017 10:39 pm

It is part of the line above it, but am i supposed to include a . because it refers to a sheet or only at the beginning of a new line of code with sheet?
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Re: 2 different excel workbooks

Postby alrodopial » Thu May 25, 2017 12:06 pm

Code: Select all
With ThisWorkbook
If .Sheets("Data").Range("T2").Value <> 1 Then
................


in the code the dot means:

"If ThisWorkbook.Sheets("Data").Range("T2").Value <> 1 Then"
it's a kind of abbreviation

you know your code so check if it is important to be there
check if the errors you are getting relate to it
alrodopial
 
Posts: 1384
Joined: Wed Dec 06, 2006 9:59 pm

Re: 2 different excel workbooks

Postby alrodopial » Thu May 25, 2017 12:10 pm

you are using two different workbooks (and not in the same workbook two different worksheets) so in theory you wont get errors from data interfering each other. What kind of errors are you getting?
alrodopial
 
Posts: 1384
Joined: Wed Dec 06, 2006 9:59 pm

Re: 2 different excel workbooks

Postby Shaun » Thu May 25, 2017 1:56 pm

Yeah, you are correct, that missing dot was my issue.
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Re: 2 different excel workbooks

Postby alrodopial » Thu May 25, 2017 4:19 pm

note that both pieces of code you provided in the first post have missing dot
alrodopial
 
Posts: 1384
Joined: Wed Dec 06, 2006 9:59 pm


Return to Help

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 49 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.