Sub UpdateLogWorksheet()
Dim historyWks As Worksheet
Dim inputWks As Worksheet
Dim nextRow As Long
Dim oCol As Long
Dim myRng As Range
Dim myCopy As Variant
Dim myCell As Range
'cells to copy from Input sheet - custName, wellName,
'contractorName , rigNum, delivTicket, Date,
'prodName1, qty1, unitSize1, unitPrice1, Total
myCopy = Array("F35", "C6", "C7", "C8", "C9", "C10", "C11", "B15", "C15", "D15", "E15", "F15", "B16", "C16", "D16", "E16", "F16", "B17", "C17", "D17", "E17", "F17", "B18", "C18", "D18", "E18", "F18", "B19", "C19", "D19", "E19", "F19", "B20", "C20", "D20", "E20", "F20", "B21", "C21", "D21", "E21", "F21", "B22", "C22", "D22", "E22", "F22", "B23", "C23", "D23", "E23", "F23", "B26", "C26", "F26", "B27", "C27", "F27", "B28", "C28", "F28", "B29", "C29", "F29", "B30", "C30", "F30", "F32", "F33", "F34", "B33", "B35")
Set inputWks = Worksheets("Input")
Set historyWks = Worksheets("Database")
With historyWks
nextRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
End With
With inputWks
Set myRng = .Range(myCopy(0))
For i = 1 To UBound(myCopy)
Set myRng = Union(myRng, .Range(myCopy(i)))
Next i
myRng.Cells(1, 1).Select
End With
With historyWks
With .Cells(nextRow, "A")
.Value = Now
.NumberFormat = "mm/dd/yyyy hh:mm:ss"
End With
.Cells(nextRow, "B").Value = Application.UserName
oCol = 3
For i = 0 To UBound(myCopy)
historyWks.Cells(nextRow, oCol).Value = inputWks.Range(myCopy(i))
oCol = oCol + 1
Next myCell
End With
'clear input cells that contain constants
With inputWks
On Error Resume Next
With .Range(myCopy).Cells.SpecialCells(xlCellTypeConstants)
.ClearContents
Application.GoTo .Cells(1) ', Scroll:=True
End With
On Error GoTo 0
End With
End Sub
Bookmarks