Not tested, but I think...
Sub EditSheet()
Dim r As Long
Dim m As Long
Dim n As Long
Dim InvoiceWks As Worksheet
Dim PreviousWks As Worksheet
Dim nextRow As Long
Dim oCol As Long
Dim myRng As Range
Dim myCopy As String
Dim myCell As Range
Dim rngTemp As Range
Dim bolTimeStampRecord As Boolean
Application.ScreenUpdating = False
'cells to copy from Previous sheet
myCopy = "O6,I10,M10,M11,M14,M15,O11,O14,O15,O38,O10,M9,O9,I9"
Set PreviousWks = Worksheets("Previous")
Set InvoiceWks = Worksheets("Invoice")
With PreviousWks
Set myRng = .Range(myCopy)
If Application.CountA(myRng) <> myRng.Cells.Count Then
MsgBox "Please fill in all the fields!"
Exit Sub
End If
End With
With InvoiceWks
Set rngTemp = RangeFound(SearchRange:=Range(.Range("B4"), .Cells(.Rows.Count, "B")), _
FindWhat:=PreviousWks.Range("O6").Text, _
LookAtWholeOrPart:=xlWhole)
If Not rngTemp Is Nothing Then
nextRow = rngTemp.Row
Else
bolTimeStampRecord = True
nextRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
End If
End With
With InvoiceWks
If bolTimeStampRecord Then
With .Cells(nextRow, "A")
.Value = Now
.NumberFormat = "hh:mm:ss"
End With
oCol = 2
For Each myCell In myRng.Cells
InvoiceWks.Cells(nextRow, oCol).Value = myCell.Value
oCol = oCol + 1
Next myCell
ThisWorkbook.Save
Else
If MsgBox("Do you want to update the current record?", vbQuestion, vbNullString) = vbYes Then
oCol = 2
For Each myCell In myRng.Cells
InvoiceWks.Cells(nextRow, oCol).Value = myCell.Value
oCol = oCol + 1
Next myCell
End If
ThisWorkbook.Save
End With
Application.ScreenUpdating = True
End Sub
Function RangeFound(SearchRange As Range, _
Optional FindWhat As String = "*", _
Optional StartingAfter As Range, _
Optional LookAtTextOrFormula As XlFindLookIn = xlValues, _
Optional LookAtWholeOrPart As XlLookAt = xlPart, _
Optional SearchRowCol As XlSearchOrder = xlByRows, _
Optional SearchUpDn As XlSearchDirection = xlPrevious, _
Optional bMatchCase As Boolean = False) As Range
If StartingAfter Is Nothing Then
Set StartingAfter = SearchRange(1)
End If
Set RangeFound = SearchRange.Find(What:=FindWhat, _
After:=StartingAfter, _
LookIn:=LookAtTextOrFormula, _
LookAt:=LookAtWholeOrPart, _
SearchOrder:=SearchRowCol, _
SearchDirection:=SearchUpDn, _
MatchCase:=bMatchCase)
End Function
Hope that helps,
Mark