"The index is not part of the selection" + VBA

fleur.31 Posted messages 3 Status Membre -  
 geosevda -
Hello,
We have a problem with our VBA programming. Here is our program:

Sub Bloucle1Bull()
Dim a, k As Integer

k = 2
Do While Worksheets("formulaire").Cells(2, 2) <> Worksheets("formulaire").Cells(k, 4)
k = k + 1
Loop

a = 2
Do While Worksheets("formulaire").Cells(k + 1, 4) <> Worksheets("BDD Call").Cells(a, 1) Or (Worksheets("BDD Call").Cells(a, 4) <= (Worksheets("bullspread").Cells(2, 3) - 100) Xor Worksheets("BDD Call").Cells(a, 4) >= (Worksheets("Bullspread").Cells(2, 3) + 100)) Or Worksheets("BDD Call").Cells(a, 7) <> Worksheets("bullspread").Cells(2, 7)
a = a + 1
Loop

''''''''''''we copy the line of the first call found for day 2 into bullspread'''''''

Worksheets("BDD Bullspread").Cells(3, 1) = Worksheets("BDD call").Cells(a, 1)
Worksheets("BDD Bullspread").Cells(3, 2) = Worksheets("BDD call").Cells(a, 3)
Worksheets("BDD Bullspread").Cells(3, 3) = Worksheets("BDD call").Cells(a, 4)
Worksheets("BDD Bullspread").Cells(3, 4) = Worksheets("BDD call").Cells(a, 5)
Worksheets("BDD Bullspread").Cells(3, 5) = Worksheets("BDD call").Cells(a, 6)
Worksheets("BDD Bullspread").Cells(3, 6) = Worksheets("BDD call").Cells(a, 7)
Worksheets("BDD Bullspread").Cells(3, 7) = Worksheets("BDD call").Cells(a, 8)
Worksheets("BDD Bullspread").Cells(3, 8) = Worksheets("BDD call").Cells(a, 9)
Worksheets("BDD Bullspread").Cells(3, 9) = Worksheets("BDD call").Cells(a, 10)

End Sub

When we run the macro, a message appears saying "the index does not belong to the selection"...

Can someone please help us??

Configuration: Windows 7 / Internet Explorer 8.0

1 réponse

gregg5l Posted messages 43 Registration date   Status Membre Last intervention   28
 
Hello;
When there is a type error in VBA "the index does not belong to the selection", it means that the code cannot find a workbook or a sheet.
So check the names of the sheets.
If the names are correct, replace Worksheets() with Sheets().
23
geosevda
 
Hello, I have the same error message, I am trying to read the lines of a text file through a message box, the code is as follows:

Dim oFSO As Scripting.FileSystemObject
Dim oTxt As Scripting.TextStream
With oTxt
Dim TestArray() As String
Dim st As String
Dim i As Integer
Dim tRows As Long
Dim tCols As Long
Dim ligne As AcadLine

Set oFSO = New Scripting.FileSystemObject
Set oTxt = oFSO.OpenTextFile(txtDWGname.Text, ForReading)

With oTxt
While Not .AtEndOfStream

st = oTxt.ReadLine
TestArray() = split(st, ";")
Dim TestArrayField As Integer
tRows = .Line
tCols = .Column
For i = 0 To tRows
MsgBox TestArray(i)
Next
Wend

End With
oTxt.Close
End With
1