I have the code below which copies input from a sales input form into the sales worksheet. The sales input form uses vlookup to return value such as category, item name and price from and inventory worksheet.
Problem is if I then later change the price of an item it cahnges the "Sales" history. as it is the formula that is pasted and not the values. I am thinking that if only the value is pasted to the "Sales" history worksheet then any changes to inventory will not affect the history. I have tried playing with the code but keep getting errors.
Sub UpdateSalesRecords()
If Range("A10").Value = Empty Then
MsgBox " No sales to update "
Exit Sub
End If
Sheets("SalesInput").Unprotect Password:=("bridget")
Sheets("Sales").Unprotect Password:=("bridget")
Dim ws As Worksheet
Dim r As Range
Set ws = Worksheets("Sales")
Set r = Range("$A$10", Range("$A$5001").End(xlUp))
For Each c In r.Cells
If c <> "" Then
c.EntireRow.Copy Destination:=ws.Range("A5001").End(xlUp).Offset(1, 0)
ws.Range("G" & Rows.Count).End(xlUp).Offset(1, 0).Value = Date
End If
Next
Set ws = Worksheets("SalesInput")
Set r = Range("$A$10", Range("$A$5001").End(xlUp))
For Each c In r.Cells
If c <> "" Then
c.EntireRow.Copy Destination:=ws.Range("A5001").End(xlUp).Offset(1, 0)
ws.Range("G" & Rows.Count).End(xlUp).Offset(1, 0).Value = Date
End If
Next
For Each c In r.Cells
If c <> "" Then
c.SpecialCells(xlCellTypeConstants, 1).Select
Selection.ClearContents
End If
Next
MsgBox "Thankyou the sales records have been updated"
Sheets("SalesInput").Protect Password:=("bridget")
Sheets("Sales").Protect Password:=("bridget")
End Sub
Bookmarks