JeffGrant
Well-known Member
- Joined
- Apr 7, 2021
- Messages
- 558
- Office Version
- 365
- Platform
- Windows
Hi all, I don't know if I am going to explain this one well at all. But here goes.
I have an array that creates a unique ID, by joining 3 array columns. Here is the VBA code.
As part of the concatenation, column B is tested for a single or double digit race number. The idea being to have no spaces in the final concatenated ID. No drama there. It works like a treat.
The data in column B, looks like this and this is where the race number comes from. No problem there either.
This data is downloaded as part of an API to a data supplier. - No problem there.
When I run the sub above, Sub CreateUniqueBDIF, as a manual start, everything works normally, the unique IDs are created correctly and pull out the number 6 in the above data correctly. No Problem there.
However, If I run the CreateUniqueBDIF sub as part of another sub to group everything together, as in the sub below, the above code that pulls out the number 6, substitutes the number 6, and any other number in the data set for the text "Da". But as you can see, there is no "Da" in "R6 1400m Mdn". I have absolutely no idea where the array construction of arr(i, 13) = arr(i, 3) & arr(i, 12) & arr(i, 9) is getting the "Da" from. "Da" does not exist anywhere.
I have tried any number of Application.Wait values and it makes no difference.
So basically, if I run the code in Sub ManualUpdate, I get a "Da" in the unique ID. If I run the Sub Create UniqueBDIF, separately it works every time.
I am absolutely at a loss on this one because I need to create the ID's on the run. Manual intervention is not really an option.
As always any and all guidance is very much appreciated.
I have an array that creates a unique ID, by joining 3 array columns. Here is the VBA code.
VBA Code:
Sub CreateUniqueBDIF()
Dim arr As Variant, rng As Range
arr = Sheet61.Range("A1").CurrentRegion
Dim i As Long
Set rng = Sheet61.Range("R1:AD1")
For i = LBound(arr, 1) + 1 To UBound(arr, 1)
'test for 1 or 2 digit race numbers
If Mid(Range("b" & i), 3, 1) = " " Then
'one digit race number
arr(i, 12) = Mid(Range("b" & i), 2, 1)
Else
'two digit race number
arr(i, 12) = Mid(Range("b" & i), 2, 2)
End If
'Create the unique Betfair ID
arr(i, 13) = arr(i, 3) & arr(i, 12) & arr(i, 9)
Next i
Sheet61.Range("R1").CurrentRegion.ClearContents
Dim rowCount As Long, columnCount As Long
rowCount = UBound(arr, 1)
columnCount = UBound(arr, 2)
Sheet61.Range("R1").Resize(rowCount, columnCount).Value = arr
End Sub
As part of the concatenation, column B is tested for a single or double digit race number. The idea being to have no spaces in the final concatenated ID. No drama there. It works like a treat.
The data in column B, looks like this and this is where the race number comes from. No problem there either.
market_name |
R6 1400m Mdn |
R6 1400m Mdn |
R6 1400m Mdn |
R6 1400m Mdn |
This data is downloaded as part of an API to a data supplier. - No problem there.
When I run the sub above, Sub CreateUniqueBDIF, as a manual start, everything works normally, the unique IDs are created correctly and pull out the number 6 in the above data correctly. No Problem there.
However, If I run the CreateUniqueBDIF sub as part of another sub to group everything together, as in the sub below, the above code that pulls out the number 6, substitutes the number 6, and any other number in the data set for the text "Da". But as you can see, there is no "Da" in "R6 1400m Mdn". I have absolutely no idea where the array construction of arr(i, 13) = arr(i, 3) & arr(i, 12) & arr(i, 9) is getting the "Da" from. "Da" does not exist anywhere.
VBA Code:
Sub ManualUpdate()
'Set Current Time
Call SetCurrentTime
'Run Download Script
Call RunAPIScript
'Application.Wait Now + TimeValue("00:00:20")
Call CreateUniqueBDIF
End Sub
I have tried any number of Application.Wait values and it makes no difference.
So basically, if I run the code in Sub ManualUpdate, I get a "Da" in the unique ID. If I run the Sub Create UniqueBDIF, separately it works every time.
I am absolutely at a loss on this one because I need to create the ID's on the run. Manual intervention is not really an option.
As always any and all guidance is very much appreciated.