Help with code!

Discuss anything related to using the program (eg. triggered betting tactics)

Moderator: 2020vision

Help with code!

Postby sagar » Fri Apr 30, 2010 2:24 pm

Hi folk,

I was working on the following code which works very well but I feel it's becoming really too redundant. You can see that each line is repeated just by changing the range value in order to write in the next column (AA, AB, AC etc.). Since I'd like to use many columns I'd like to avoid writing an endless code. Do you have any idea of how to make it shorter? I hope this is clear... This is the code:


Private Sub Worksheet_Change(ByVal Target As Range)
Dim iRow As Integer
Dim iCol As Integer
Dim cell As Object

For Each cell In Target
iRow = cell.Row
iCol = cell.Column

' Update Max and Min Back Values
If iCol = 6 And iRow > 4 And iRow < 1000 Then

Application.EnableEvents = False
If IsEmpty(Range("AA" & iRow).Value) And cell.Value = Range("AA1").Value Then Range("AA" & iRow).Value = Range("G" & iRow).Value
If IsEmpty(Range("AB" & iRow).Value) And cell.Value = Range("AB1").Value Then Range("AB" & iRow).Value = Range("G" & iRow).Value
If IsEmpty(Range("AC" & iRow).Value) And cell.Value = Range("AC1").Value Then Range("AC" & iRow).Value = Range("G" & iRow).Value


If Not IsEmpty(Range("AA" & iRow).Value) Then
If cell.Value = Range("AA1").Value And Range("AA" & iRow).Value < Range("G" & iRow).Value Then Range("AA" & iRow).Value = Range("G" & iRow).Value
If cell.Value = Range("AB1").Value And Range("AB" & iRow).Value < Range("G" & iRow).Value Then Range("AB" & iRow).Value = Range("G" & iRow).Value
If cell.Value = Range("AC1").Value And Range("AC" & iRow).Value < Range("G" & iRow).Value Then Range("AC" & iRow).Value = Range("G" & iRow).Value

End If

Application.EnableEvents = True
End If

Next cell

End Sub
sagar
 
Posts: 27
Joined: Sat Aug 04, 2007 2:18 pm

Postby GaryRussell » Fri Apr 30, 2010 3:19 pm

You can use the following syntax
Code: Select all
Range(Cells(r,c))

So for example
Code: Select all
for c=27 to 29
   If IsEmpty(Range(cells(iRow,c)).Value) And cell.Value = Range(cells(1,c)).Value Then Range(cells(iRow,c)).Value = Range(cells(iRow,7)).Value
next
User avatar
GaryRussell
Site Admin
 
Posts: 9872
Joined: Fri Nov 18, 2005 8:09 pm
Location: Birmingham, UK

Postby GaryRussell » Fri Apr 30, 2010 3:30 pm

In fact you are only referring to single cells at a time so you don't need to use range at all. For example:-
Code: Select all
for c=27 to 29
   If IsEmpty(cells(iRow,c).Value) And cell.Value = cells(1,c).Value Then cells(iRow,c).Value = cells(iRow,7).Value
next
User avatar
GaryRussell
Site Admin
 
Posts: 9872
Joined: Fri Nov 18, 2005 8:09 pm
Location: Birmingham, UK

Postby sagar » Mon May 03, 2010 3:07 am

Thanks you so much Gary!
sagar
 
Posts: 27
Joined: Sat Aug 04, 2007 2:18 pm


Return to Discussion

Who is online

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