A
A
Alexander Vladimirov2018-05-17 23:46:23
Visual Basic
Alexander Vladimirov, 2018-05-17 23:46:23

Why does subscript out of range give error?

Why is it giving an error Why is it giving a subscript out of range error?
in all the line where is ActiveWorkbook.Worksheets(List).Cells(k, 2
)

spoiler
Option Base 1
Dim Ном1 As Integer, Группа1 As Integer, Ячейка As Integer
Dim Инф1 As Integer, Мат1 As Integer, ПСП1 As Integer
Dim ПТАКТ1 As Integer, Колдв As Integer
Dim Србал(1 To 4) As Currency
Public Фам1 As String
Public List As String
Public k As Integer
Private Sub Дан_Экзамен_Initialize()
k = 4
Workbooks.Add
Ном1 = ActiveWorkbook.Worksheets(List).Cells(k, 1)
Группа1 = ActiveWorkbook.Worksheets(List).Cells(k, 2)
Фам1 = ActiveWorkbook.Worksheets(List).Cells(k, 3)
Инф1 = ActiveWorkbook.Worksheets(List).Cells(k, 4)
Мат1 = ActiveWorkbook.Worksheets(List).Cells(k, 5)
ПСП1 = ActiveWorkbook.Worksheets(List).Cells(k, 6)
ПТАКТ1 = ActiveWorkbook.Worksheets(List).Cells(k, 7)
Колдв = ActiveWorkbook.Worksheets(List).Cells(k, 8)
Номер.Value = Ном1
Ввод_Фам.Value = Фам1
Ввод_Группа.Value = Группа1
Выбор_оценка.Value = Инф1
Выбор_Оценка1.Value = Мат1
Выбор_Оценка2.Value = ПСП1
Выбор_Оценка3.Value = ПТАКТ1
Ввод_дв.Value = Колдв
For j = 1 To 4
Србал(j) = ActiveWorkbook.Worksheets(List).Cells(14, j + 3)
Next j
Вывод_ср1.Value = Србал(1)
Вывод_ср2.Value = Србал(2)
Вывод_ср3.Value = Србал(3)
Вывод_ср4.Value = Србал(4)
Выбор_оценка.RowSource = "k5:k8"
Выбор_Оценка1.RowSource = "k5:k8"
Выбор_Оценка2.RowSource = "k5:k8"
Выбор_Оценка3.RowSource = "k5:k8"
End Sub
Private Sub Выбор_Оценка_Change()
Инф1 = Выбор_оценка.Value
End Sub
Private Sub Выбор_Оценка1_Change()
Мат1 = Выбор_Оценка1.Value
End Sub
Private Sub Выбор_Оценка2_Change()
ПСП1 = Выбор_Оценка2.Value
End Sub
Private Sub Выбор_Оценка3_Change()
ПТАКТ1 = Выбор_Оценка3.Value
End Sub
Private Sub Кн_Ввод_Click()
ActiveWorkbook.Worksheets(List).Cells(k, 4) = Инф1
ActiveWorkbook.Worksheets(List).Cells(k, 5) = Мат1
ActiveWorkbook.Worksheets(List).Cells(k, 6) = ПСП1
ActiveWorkbook.Worksheets(List).Cells(k, 7) = ПТАКТ1
Колдв = 0
For i = 4 To 7
If ActiveWorkbook.Worksheets(List).Cells(k, i) = 2 Then Колдв = Колдв + 1
Next i
ActiveWorkbook.Worksheets(List).Cells(k, 8) = Колдв
Ввод_дв.Value = Колдв
For j = 1 To 4
Србал(j) = 0
For M = 4 To 13
Србал(j) = Србал(j) + ActiveWorkbook.Worksheets(List).Cells(M, j + 3)
Next M
Србал(j) = Србал(j) / 10
ActiveWorkbook.Worksheets(List).Cells(14, j + 3) = Србал(j)
Next j
Вывод_ср1.Value = Србал(1)
Вывод_ср2.Value = Србал(2)
Вывод_ср3.Value = Србал(3)
Вывод_ср4.Value = Србал(4)
End Sub
Private Sub Кн_Выход_Click()
Dim M As String, T As String, R As String
Dim St As String
M = "Хотите закончить работу?"
St = vbYesNo + vbCritical + vbDefaultButton2
T = "Выход из программы!"
R = MsgBox(M, St, T)
If R = vbYes Then
Unload Me
End If
End Sub
Private Sub Кн_Редактировать_Click()
Номер.Enabled = True
Ввод_Фам.Enabled = True
Выбор_оценка.Enabled = True
Выбор_Оценка3.Enabled = True
Выбор_Оценка1.Enabled = True
Выбор_Оценка2.Enabled = True
Ввод_Группа.Enabled = True
End Sub
Private Sub Счет_SpinDown()
Номер.Enabled = False
Ввод_Фам.Enabled = False
Выбор_оценка.Enabled = False
Выбор_Оценка3.Enabled = False
Выбор_Оценка1.Enabled = False
Выбор_Оценка2.Enabled = False
Ввод_Группа.Enabled = False
If k > 4 Then k = k + 1
Ном1 = ActiveWorkbook.Worksheets(List).Cells(k, 1)
Группа1 = ActiveWorkbook.Worksheets(List).Cells(k, 2)
Фам1 = ActiveWorkbook.Worksheets(List).Cells(k, 3)
Инф1 = ActiveWorkbook.Worksheets(List).Cells(k, 4)
Мат1 = ActiveWorkbook.Worksheets(List).Cells(k, 5)
ПСП1 = ActiveWorkbook.Worksheets(List).Cells(k, 6)
ПТАКТ1 = ActiveWorkbook.Worksheets(List).Cells(k, 7)
Колдв = ActiveWorkbook.Worksheets(List).Cells(k, 8)
Номер.Value = Ном1
Ввод_Фам.Value = Фам1
Ввод_Группа.Value = Группа1
Выбор_оценка.Value = Инф1
Выбор_Оценка1.Value = Мат1
Выбор_Оценка2.Value = ПСП1
Выбор_Оценка3.Value = ПТАКТ1
Ввод_дв.Value = Колдв
End Sub
Private Sub Счет_SpinUp()
Номер.Enabled = False
Ввод_Фам.Enabled = False
Выбор_оценка.Enabled = False
Выбор_Оценка3.Enabled = False
Выбор_Оценка1.Enabled = False
Выбор_Оценка2.Enabled = False
Ввод_Группа.Enabled = False
If k < 13 Then k = k + 1
Ном1 = ActiveWorkbook.Worksheets(List).Cells(k, 1)
Группа1 = ActiveWorkbook.Worksheets(List).Cells(k, 2)
Фам1 = ActiveWorkbook.Worksheets(List).Cells(k, 3)
Инф1 = ActiveWorkbook.Worksheets(List).Cells(k, 4)
Мат1 = ActiveWorkbook.Worksheets(List).Cells(k, 5)
ПСП1 = ActiveWorkbook.Worksheets(List).Cells(k, 6)
ПТАКТ1 = ActiveWorkbook.Worksheets(List).Cells(k, 7)
Колдв = ActiveWorkbook.Worksheets(List).Cells(k, 8)
Номер.Value = Ном1
Ввод_Фам.Value = Фам1
Ввод_Группа.Value = Группа1
Выбор_оценка.Value = Инф1
Выбор_Оценка1.Value = Мат1
Выбор_Оценка2.Value = ПСП1
Выбор_Оценка3.Value = ПТАКТ1
Ввод_дв.Value = Колдв
End Sub
Sub Auto_Open()
Дан_Экзамен.Show
End Sub

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shushpanio, 2018-05-18
@shushpanio

Alexander Vladimirov , You have not declared the creation of a sheet after the creation of the book.
Add a line here
Private Sub Dan_Exam_Initialize()
k = 4
Workbooks.Add
Nom1 = ActiveWorkbook.Worksheets(List).Cells(k, 1)
And more when you refer to the direct name of the sheet (in your case, List), then it must be written not List but "List" in quotes.
PS Then the macro will give an error on the line No.Value = Nom1
But unfortunately there is not much time to rewrite the entire macro for you.
But the answer to your question is here :-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question