QUESTION :
I have created a function called =SalePrice that will markup the values found on “Cost Price” column by a percentage for a product.
Now I want to be able to check on an adjacent column called UpdatePrice to see if the product’s sale price must remain unchanged.
So I want to create a function that will do:
IF(UpdatePrice = "Update Price",SalePrice,KeepOldValue)
So I want to update values in column F only if in V column = “Update Price”, else the value in F column should remain unchanged.
How would you do that?
ANSWER :
It looks like you are using a table, which is a good start. Add some column names, like UpdatePrice instead of CustomField10. Then use those column names in a formula, like =IF([@UpdatePrice]="Update Price", [@SalePrice], [@FullPrice])
.
So, What I did was:
Create a macro that
'Select UpdatePrices sheet.
Sheets("UpdatePrices").Select
'Select All the rows containing values and delete them.
Application.Goto Reference:="R2C1"
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Application.CutCopyMode = False
Selection.EntireRow.Delete
'Select the ERP sheet with the latest values and copy paste them to the UpdatePrices Sheet
Sheets("ManagerImportSheet").Select
Application.Goto Reference:="R2C1"
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
Sheets("UpdatePrices").Select
Application.Goto Reference:="R2C1"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Select the Old Sale Prices and copy them.
Application.Goto Reference:="R2C1"
Selection.End(xlDown).Select
ActiveCell.Offset(0, 5).Range("UpdatePrices[[#Headers],[Code]]").Select
Range("UpdatePrices[SalePrice]").Select
'Range("F1476").Activate
Application.CutCopyMode = False
Selection.Copy
'Go to Data Sheet and Paste them for later use in formula
Sheets("Data").Select
Application.Goto Reference:="R2C3"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Clear contents of Sale Price and Cost Price columns
Sheets("UpdatePrices").Select
Application.CutCopyMode = False
Selection.ClearContents
Application.Goto Reference:="R2C1"
Selection.End(xlDown).Select
ActiveCell.Offset(0, 19).Range("UpdatePrices[[#Headers],[Code]]").Select
Range("UpdatePrices[CustomFields.8220bcd8c4284ee9b653cced0445a0cd]").Select
Selection.ClearContents
'Enter the named formula to calculate the new CostPrices.
Application.Goto Reference:="R2C20"
ActiveCell.FormulaR1C1 = "=CostPrice"
Application.Goto Reference:="R2C6"
'Enter a formula that will check the "Update Price" Column named '[@[CustomFields.49d90e39488947ef899044e3c56a23f5] and if it is equal to
' "Update Price" then use the named formula SalePrice else, copy the old price into
' Place from the Data sheet.
ActiveCell.FormulaR1C1 = _
"=IF([@[CustomFields.49d90e39488947ef899044e3c56a23f5]]=""Update Price"",SalePrice,Data!RC[-3])"
What is left to do is probably lock the appropriate sheets/cells.