Results 1 to 14 of 14

Thread: Need help on VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    here you try this
    Option Explicit
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim i As Integer, dt1 As Date, dt2 As Date
    Dim j As Integer, k As Integer
    Application.EnableEvents = False
    If Left$(Target.Address, 2) = "$B" Then
        If InStr(1, Target.Address, ":") = 0 Then
            If Val(Range("$A$" & Target.Row)) <> 0 And Val(Target) <> 0 Then
                dt1 = Range("$A$" & Target.Row).Value
                dt2 = Target.Value
                i = DateDiff("h", dt1, dt2)
                j = DateDiff("h", #12:00:00 AM#, dt1) + 4
                For k = j To j + i
                    Cells(Target.Row, k) = 1
                Next
            End If
        End If
    End If
    Application.EnableEvents = True
    End Sub
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •