Excel VBS Runtime error '9': Subscript out of range

Ответить
lАртёмl
Сообщения:1
Зарегистрирован:05 апр 2013, 19:25

05 апр 2013, 19:50

Выдает ошибку Runtime error '9': Subscript out of range не могу с ней разобраться

Код: Выделить всё

Private Sub CommandButton1_Click()
Dim cost(10) As Double

Dim amount(10, 5) As Integer

Dim pay(8) As Double

Dim amount_n(10) As Integer

Dim day As Integer

Dim sumpay As Double

Dim m As Integer, p As Integer
For m = 1 To 10
amount_n(m) = 0

Next
For p = 1 To 8

    pay(p) = 0

Next
sumpay = 0

day = 0
Sheets("Start").Select

For m = 1 To 10

cost(m) = Cells(3 + m, 2)

Next
For m = 1 To 10

    For p = 1 To 7

        amount(m, p) = Cells(3 + m, 2 + p)

    Next p

Next m
Sheets("Results").Select

Cells(1, 1) = " Количество изготовленных деталей "

Cells(2, 1) = " Наименование телевизора "

Cells(2, 2) = " Стоимость работ "

Cells(2, 3) = " Отремонтировано "

Cells(3, 3) = " 1-й день "

Cells(3, 4) = " 2-й день "

Cells(3, 5) = " 3-й день "

Cells(3, 6) = " 4-й день "

Cells(3, 7) = " 5-й день "

Cells(3, 8) = " 6-й день "

Cells(3, 9) = " 7-й день "

Cells(3, 7) = " Всего "

Cells(4, 1) = "самсунг"

Cells(5, 1) = "филипс"

Cells(6, 1) = "сони"

Cells(7, 1) = "айсер"

Cells(8, 1) = "шарп"

Cells(9, 1) = "лджи"

Cells(10, 1) = "витязь"

Cells(11, 1) = "хп"

Cells(12, 1) = "зануси"

Cells(13, 1) = "урал"

For m = 1 To 10

    Cells(3 + i, 2) = cost(m)

    For p = 1 To 7

        Cells(3 + m, 2 + p) = amount(m, p)

        amount_n(m) = amount_n(m) + amount(m, p)
        
        Next p

    Cells(3 + m, 10) = amount_n(m)

Next m
Cells(15, 1) = " Наименование телевизора "

Cells(15, 2) = " Стоимость работ "

Cells(15, 3) = " Отремонтировано "

Cells(16, 3) = " 1-й день "

Cells(16, 4) = " 2-й день "

Cells(16, 5) = " 3-й день "

Cells(16, 6) = " 4-й день "

Cells(16, 7) = " 5-й день "

Cells(16, 8) = " 6-й день "

Cells(16, 9) = " 7-й день "

Cells(16, 10) = " Всего "

Cells(17, 1) = " Самсунг "

Cells(18, 1) = " филипс "

Cells(19, 1) = " сони "

Cells(20, 1) = " айсер "

Cells(21, 1) = " шарп "

Cells(22, 1) = " лджи "

Cells(23, 1) = " витязь "

Cells(24, 1) = " хп "

Cells(25, 1) = " зануси "

Cells(26, 1) = " урал "

For m = 1 To 10

 For p = 1 To 7
 
   Cells(16 + m, 2 + p) = amount(m, p) * cost(m)
   
    pay(p) = pay(p) + amount(m, p) * cost(m)

    pay(8) = pay(8) + amount(m, p) * cost(m)

   Next p

    Cells(16 + m, 2) = cost(m)

    Cells(16 + m, 8) = cost(m) * amount_n(m)
 Next m

    

    
For p = 1 To 7

    Cells(27, 2 + p) = pay(p)

    If pay(p) > sumpay Then

    sumpay = pay(p)

    day = p

    End If
    
    Next
Cells(27, 8) = pay(8)

Cells(28, 1) = " Зарабаток за неделю "

Cells(28, 5) = pay(8)

Cells(29, 1) = "День с максимальным зарабатком"

Cells(29, 5) = day

Cells(29, 6) = " Заработано "

Cells(29, 8) = sumpay


End Sub
http://zalil.ru/34414325 (сам файлик)
Ответить