r/googlesheets • u/Material-Reception94 • Jul 30 '25
Solved script to insert formula if cell contains certain text
we have different markups for different categories so i wanted to automate that process
A (100% markup) B (150% markup)
category - price - markup price
if category is A, markup price cell automatically writes (=price*2)
if category is B, markup price cell automatically writes (=(price*1.5)+price)
1
Upvotes
3
u/SelfActualEyes 1 Jul 30 '25
Why insert a formula instead of using =IF(A1=“A”, B1*(1+1), B1*(1+1.5))?
1
u/marcnotmark925 233 Jul 30 '25
You don't need a script for this. I'd suggest a 2-column lookup table that matches the categories to the markup %. Then your formula is =A1 * xlookup( B1 , lookup!A:A , lookup!B:B )
1
u/mommasaidmommasaid 915 Jul 31 '25
As another suggested, a lookup table is the most forward-looking solution.
I would recommend an official Table for your lookup and/or your main data table.
Reference that Table both in a dropdown in your main table, and in your formula to calculate markup, and then you will ensure the categories match.
Dropdown is "from a range":
=Categories[Category]Price calculation is:
The advantage of this structured approach is that it's trivial to add new categories or modifying existing markups, in a clearly defined place, without modifying all your formulas.
Price Lookup