Лекция: Перемещение на строку вниз
Private Sub SpinButton1_SpinDown()
i = ActiveCell.Row + 1
If Worksheets(1).Rows(i).Cells(1).Value <> "" Then
Worksheets(1).Rows(ActiveCell.Row + 1).Select
UserForm1.TextBox1.Text = Worksheets(1).Rows(i).Cells(1).Value
UserForm1.TextBox2.Text = Worksheets(1).Rows(i).Cells(2).Value
UserForm1.TextBox3.Text = Worksheets(1).Rows(i).Cells(3).Value
UserForm1.TextBox4.Text = Worksheets(1).Rows(i).Cells(4).Value
UserForm1.TextBox5.Text = Worksheets(1).Rows(i).Cells(5).Value
UserForm1.TextBox6.Text = Worksheets(1).Rows(i).Cells(6).Value
End If
End Sub
Перемещение на строку вверх.
'Перемещение на строку вверх.
Private Sub SpinButton1_SpinUp()
i = ActiveCell.Row — 1
If i > 2 Then
Worksheets(1).Rows(ActiveCell.Row — 1).Select
UserForm1.TextBox1.Text = Worksheets(1).Rows(i).Cells(1).Value
UserForm1.TextBox2.Text = Worksheets(1).Rows(i).Cells(2).Value
UserForm1.TextBox3.Text = Worksheets(1).Rows(i).Cells(3).Value
UserForm1.TextBox4.Text = Worksheets(1).Rows(i).Cells(4).Value
UserForm1.TextBox5.Text = Worksheets(1).Rows(i).Cells(5).Value
UserForm1.TextBox6.Text = Worksheets(1).Rows(i).Cells(6).Value
End If
End Sub
Функция поиска первой свободной строки в таблице
Public Function EndFind()
Dim i As Byte
i = 2
While Worksheets(1).Rows(i).Cells(2).Formula > ""
I = i + 1
Wend
EndFind = i
End Function