Se pretendermos preencher linhas sequencialmente (nas colunas B e C) com dados, que poderemos digitar a partir de InputBoxs, como no exemplo:
uma via poderá ser fazê-lo através do seguinte código, associado a um botão de comando:
CÓDIGO:
Const Horas_Title = "Inserção de Hora de Entrada/Saída"
Type Util_Horas
Hora_Inicio As Variant
Hora_Fim As Variant
End Type
Sub Enter_Horas()
Dim Horas As Util_Horas
Dim MySheet As String
Dim RNum As Integer
MySheet = ActiveSheet.Name
Worksheets(MySheet).Select
Horas = Get_Util_Horas
If IsNull(Horas.Hora_Inicio) Then
Exit Sub
Else
RNum = Sheets(MySheet).Range("B" & Rows.Count).End(xlUp).Row + 1
With Horas
Cells(RNum, 2).Value = .Hora_Inicio
Cells(RNum, 3).Value = .Hora_Fim
End With
End If
End Sub
Function Get_Util_Horas() As Util_Horas
Dim Item As Util_Horas
Dim Tmp As Variant
With Item
Tmp = InputBox(Prompt:="Digite a Hora de Entrada", Title:=Horas_Title)
If Tmp = "" Then
Exit Function
Else
.Hora_Inicio = Tmp
End If
Tmp = InputBox(Prompt:="Digite a Hora de Saída", Title:=Horas_Title)
If Tmp = "" Then
Exit Function
Else
.Hora_Fim = Tmp
End If
End With
Get_Util_Horas = Item
End Function