Sub maintenance_entry()
Dim data_range, cell, record_range As Range
Dim record_row, rows_count As Integer
Set data_range = Range(Cells(2, 2), Cells(11, 2))
Set record_range = Sheets("Maintenance Record").ListObjects("maintenance").DataBodyRange
rows_total = record_range.Rows.Count
rows_count = 1
If Cells(1, 6).Value = "" Or Cells(1, 2).Value = "" Then
MsgBox ("Enter machine name, enter date")
Exit Sub
End If
For Each cell In data_range
If IsEmpty(cell) = False Then
record_range(rows_total + rows_count, 2) = cell.Offset(0, -1)
record_range(rows_total + rows_count, 4) = Cells(1, 6).Value
record_range(rows_total + rows_count, 6) = cell.Value
record_range(rows_total + rows_count, 5) = Cells(1, 2).Value
record_range(rows_total + rows_count, 5).NumberFormat = "mm/dd/yyyy"
If cell.Value = "Replace" Then
record_range(rows_total + rows_count, 3) = 1
End If
record_range(rows_total + rows_count, 7) = cell.Offset(0, 1).Value
record_range(rows_total + rows_count, 1) = cell.Offset(0, 2).Value
rows_count = rows_count + 1
End If
Next cell
If IsEmpty(Cells(12, 2)) = False Then
record_range(rows_total + rows_count, 2) = Cells(12, 2).Value
record_range(rows_total + rows_count, 4) = Cells(1, 6).Value
record_range(rows_total + rows_count, 6) = Cells(12, 3).Value
record_range(rows_total + rows_count, 5) = Cells(1, 2).Value
record_range(rows_total + rows_count, 5).NumberFormat = "mm/dd/yyyy"
If Cells(12, 3).Value = "Replace" Then
record_range(rows_total + rows_count, 3) = 1
End If
record_range(rows_total + rows_count, 7) = Cells(12, 4).Value
record_range(rows_total + rows_count, 1) = Cells(12, 5).Value
End If
Range(Range("B1"), Range("d12")).ClearContents
Cells(12, 5).ClearContents
Cells(1, 6).ClearContents
End Sub