Converting data table into time table

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hello Rocky.ca,

I have added a VBA macro to your workbook. This will automatically validate the time entries and fill in the time table. You can download the file from http://www.mediafire.com/?t3grbg93vk0to9c. Here is the Worksheet_Change event macro code.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

  Dim R As Long
  
    If Target.Cells.Count > 1 Then Exit Sub
    
    If Not Intersect(Target, Union(Range("Start_Time"), Range("End_Time"))) Is Nothing Then
    
       If Target.Value < 8 Or Target.Value > 20 Then
          MsgBox "Please enter a time from 0800 to 2000.", vbExclamation
          Exit Sub
       End If
       
       If Not Intersect(Target, Range("End_Time")) Is Nothing Then
          If Target.Value < Target.Offset(0, -1) Then
             MsgBox "Ending Time must be later than the Starting Time.", vbExclamation
             Exit Sub
          End If
       End If
       
       For R = Cells(Target.Row, "B").Value To Cells(Target.Row, "C").Value
         Cells(R, "B") = Cells(Target.Row, "A")
         Cells(R, "C") = Cells(Target.Row, "D")
       Next R
      
    End If
    

End Sub
Sincerely,
Leith Ross
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top