IF THEN error

ProphetofProfit

New Member
Joined
Feb 28, 2011
Messages
28
IF THEN is the problem, I don't know why. I'm not a professional coder, I just do this stuff for the thrills :laugh:. I'm trying to find the value of Sheets("Odds").Cells(r, 18).Value in the sheet "Get Odds" and then copy the two cells to the right back into "Odds".

You can see that I'm running another macro in this macro, which outputs the cells which I need to copy and paste. This other macro takes about 5 seconds to complete, will my macro automatically give this "Cmdcalculate_click" macro enough time to finish?

------------------------
Sub BackTest()
Dim i
Dim r
For r = Sheets("Summary").Range("E1") To Sheets("Odds").Range("E2")

'Copy predicted goals to "Get Odds"

Sheets("Get Odds").Cells(1, 3).Value = Sheets("Odds").Cells(r, 7).Value
Sheets("Get Odds").Cells(2, 3).Value = Sheets("Odds").Cells(r, 8).Value

'Run Macro

Application.Run "CmdCalculate_Click"

'Copy over and under 2.5 probabilities

Sheets("Odds").Cells(r, 11).Value = Sheets("Get Odds").Range("B19").Value
Sheets("Odds").Cells(r, 12).Value = Sheets("Get Odds").Range("B20").Value

'Search for the asian handicap in "Get Odds"

For i = Sheets("Get Odds").Range("A32") To Sheets("Get Odds").Range("A56")
If
Sheets("Get Odds").Cells(i, 1).Value = Sheets("Odds").Cells(r, 18).Value
Then
Sheets("Odds").Cells(r, 21).Value = Sheets("Get Odds").Cells(i, 2).Value
Sheets("Odds").Cells(r, 22).Value = Sheets("Get Odds").Cells(i, 3).Value
Else
Next i
Next r
End Sub
--------------------
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
You need to keep the conditional and "Then" on the same line as the If.

Code:
Sub BackTest()
Dim i
Dim r
For r = Sheets("Summary").Range("E1") To Sheets("Odds").Range("E2")

'Copy predicted goals to "Get Odds"
 
  Sheets("Get Odds").Cells(1, 3).Value = Sheets("Odds").Cells(r, 7).Value
  Sheets("Get Odds").Cells(2, 3).Value = Sheets("Odds").Cells(r, 8).Value

'Run Macro

  Application.Run "CmdCalculate_Click"

'Copy over and under 2.5 probabilities
 
  Sheets("Odds").Cells(r, 11).Value = Sheets("Get Odds").Range("B19").Value
  Sheets("Odds").Cells(r, 12).Value = Sheets("Get Odds").Range("B20").Value

'Search for the asian handicap in "Get Odds"

For i = Sheets("Get Odds").Range("A32") To Sheets("Get [COLOR=Black]Odds").Range("A56")
[/COLOR] [COLOR=Black]If Sheets("Get Odds").Cells(i, 1).Value = Sheets("Odds").Cells(r, 18).Value[/COLOR][COLOR=Black] Then[/COLOR]
  Sheets("Odds").Cells(r, 21).Value = Sheets("Get Odds").Cells(i, 2).Value
  Sheets("Odds").Cells(r, 22).Value = Sheets("Get Odds").Cells(i, 3).Value
End If
Next i
Next r
End Sub
 
Upvote 0
Thanks, that solved it.

My next error is this:

Code:
Application.Run "CmdCalculate_Click"

I'm trying to run another macro, which I didn't create, which is in the same worksheet, and works fine. Here is the code for this other macro:

Code:
Private Sub CmdCalculate_Click()
    'initialise values
    For i = 0 To 11
        For j = 0 To 11

But there is an error:

Run-time error '1004':

Application-defined or object defined error.
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,676
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top