2016-07-22 2 views
-1

を使用してどのようなユーザ入力によって変更することに時間を必要としています。そこでは、私たちは、時間と実行を開始している(それの写真があります)時間。この情報は、シート3に渡され、私は終了時間が実行時間に応じて変化することにしたいです。例えば、ユーザ入力は、時刻=午後1時とexcution時間= 30分を開始場合。私は、コードはシート3 =午後1時30分に終了時刻に入れたいと思います。ここで私が持っている現在のコードです:enter image description here私はだから私は、私は、ユーザーから必要な情報のリストを持っているシート1エクセルでVBA

Sub findData() 
    Dim workflow As String 
    Dim finalrow As Integer 
    Dim i As Integer 

    With Sheets("Sheet1") 
     workflow = .Range("C5").Value 
     servergri = .Range("C9").Value 
     gridf = .Range("C9").Value 
     StartTime = .Range("c11").Value 
    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 


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

End Sub 

答えて

0

は、これはそれを行うだろうが、あなたは、ユーザーが唯一の時間を分単位で入力することを確認する必要があります。 15分、1時間または "15" のEG "60"。彼らはラベルを入力すべきではありません。

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 
関連する問題