Table Row .Value

  Kiến thức lập trình

I am having a problem with type mismatch. I want to detect if there was a change made to a cell and then subtract two values. Also how would I go about referencing a table row and use that instead of the files row numbers?

this is the code im trying

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim x As Workbook
Set x = Workbooks("DOWNTIME PROGRAM - ZJ.xlsm")

Dim StartTimeRange As Range
Dim EndTimeRange As Range
Dim DurationRange As Range
Dim i As Long

Set StartTimeRange = x.Sheets("Downtime").Range("StartTimeRange")(i) 'Turns defind column cells for start time into ranges for the code (B16:B50)
Set EndTimeRange = x.Sheets("Downtime").Range("EndTimeRange")(i) 'Turns defind column cells for end time into ranges for the code (H16:H50)
Set DurationRange = x.Sheets("Downtime").Range("DurationRange")(i)

If Not Intersect(Target, Range("B16:B50")) Is Nothing Then
        DurationRange.Value = EndTimeRange.Value - StartTimeRange.Value
End If
End Sub