Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我需要一个时间来改变什么用户输入使用VBA_Vba_Excel - Fatal编程技术网

我需要一个时间来改变什么用户输入使用VBA

我需要一个时间来改变什么用户输入使用VBA,vba,excel,Vba,Excel,因此,在excel表1上,我有一个我需要从用户那里获得的信息列表(有一张图片),上面有开始时间和执行时间。此信息将传递到sheet3,我希望根据执行时间更改结束时间。例如,如果用户输入开始时间=下午1:00,执行时间=30分钟。我想把代码放在第3页的结束时间=下午1:30。以下是我的当前代码: 这样就可以了,但您需要确保用户只以分钟为单位输入时间。例如“60”持续1小时或“15”持续15分钟。他们不应该输入标签 Sub findData() Dim workflow As String Dim

因此,在excel表1上,我有一个我需要从用户那里获得的信息列表(有一张图片),上面有开始时间和执行时间。此信息将传递到sheet3,我希望根据执行时间更改结束时间。例如,如果用户输入开始时间=下午1:00,执行时间=30分钟。我想把代码放在第3页的结束时间=下午1:30。以下是我的当前代码:


这样就可以了,但您需要确保用户只以分钟为单位输入时间。例如“60”持续1小时或“15”持续15分钟。他们不应该输入标签

Sub findData()
Dim workflow As String
Dim finalrow As Integer
Dim i As Integer
Dim StartTime as Date
Dim ExecutionTime as Long

With Sheets("Sheet1")
    workflow = .Range("C5").Value
    servergri = .Range("C9").Value
    gridf = .Range("C9").Value
    On Error Goto Next
    StartTime = .Range("c11").Value
    If Err Then
        MsgBox "You didn't enter a valid start time.", vbExclamation
        Exit Sub
    End If
    ExecutionTime = .Range("c16").Value
    If Err Then
        MsgBox "You didn't enter a valid execution time.", vbExclamation
        Exit Sub
    End If
    On Error Goto 0
End With

With Sheets("Sheet3")
    finalrow = .Range("C" & Rows.Count).End(xlUp).Row

    For i = 5 To finalrow
        If .Cells(i, 3) = workflow And (.Cells(i, 4) = servergri Or .Cells(i, 5) = gridf) Then
            .Rows(i).Insert
            'Add new information to the new row.
            'The new row number is still = i

            .Cells(i, 3) = workflow
            .Cells(i, 4) = servergri
            .Cells(i, 6) = StartTime
                .Cells(i, 3).Resize(2, 4).Interior.ColorIndex = 8

            'You don't mention where this time should go on Sheet 3, so I used Cell(i, 9)
            'TimeSerial(Hours, Minutes, Seconds)
            .Cells(I, 9).Value = StartTime + TimeSerial(0, ExecutionTime, 0) 
            .Cells(I, 9).NumberFormat = "hh:mm"

            'If you only want to add one row then your should exit the loop
            Exit For
        End If
    Next
End With
End Sub
Sub findData()
Dim workflow As String
Dim finalrow As Integer
Dim i As Integer
Dim StartTime as Date
Dim ExecutionTime as Long

With Sheets("Sheet1")
    workflow = .Range("C5").Value
    servergri = .Range("C9").Value
    gridf = .Range("C9").Value
    On Error Goto Next
    StartTime = .Range("c11").Value
    If Err Then
        MsgBox "You didn't enter a valid start time.", vbExclamation
        Exit Sub
    End If
    ExecutionTime = .Range("c16").Value
    If Err Then
        MsgBox "You didn't enter a valid execution time.", vbExclamation
        Exit Sub
    End If
    On Error Goto 0
End With

With Sheets("Sheet3")
    finalrow = .Range("C" & Rows.Count).End(xlUp).Row

    For i = 5 To finalrow
        If .Cells(i, 3) = workflow And (.Cells(i, 4) = servergri Or .Cells(i, 5) = gridf) Then
            .Rows(i).Insert
            'Add new information to the new row.
            'The new row number is still = i

            .Cells(i, 3) = workflow
            .Cells(i, 4) = servergri
            .Cells(i, 6) = StartTime
                .Cells(i, 3).Resize(2, 4).Interior.ColorIndex = 8

            'You don't mention where this time should go on Sheet 3, so I used Cell(i, 9)
            'TimeSerial(Hours, Minutes, Seconds)
            .Cells(I, 9).Value = StartTime + TimeSerial(0, ExecutionTime, 0) 
            .Cells(I, 9).NumberFormat = "hh:mm"

            'If you only want to add one row then your should exit the loop
            Exit For
        End If
    Next
End With
End Sub