Skip to main content
Google Sheets Integration

Oil Prices in Google Sheets

Import WTI, Brent crude, natural gas, and diesel prices with Apps Script. Works on desktop, mobile, and tablet.

Choose Your Method

Three ways to get oil prices in Google Sheetsβ€”pick the one that fits your workflow

πŸ“‹

Manual Copy-Paste

Copy prices from our website into your spreadsheet

  • βœ“Free forever
  • βœ“No coding required
  • βœ—No automation
  • βœ—Error-prone
Best for: One-time lookups
Recommended
⚑

Apps Script

Custom functions that auto-update with triggers

  • βœ“Full automation
  • βœ“Custom refresh intervals
  • βœ“Complete control
  • ~5-min setup
Best for: Developers & power users
πŸ”Œ

Google Add-on

Install from marketplace, configure in sidebar

  • βœ“One-click install
  • βœ“No coding
  • βœ“Auto-refresh built in
  • ~$15/mo (paid plans)
Best for: Non-technical users

Get Crude Oil Prices

Step 1: Open Apps Script Editor

  1. In Google Sheets, click Extensions - Apps Script
  2. Delete any existing code
  3. Paste the code below and save
# Crude Oil Price Function
function OIL_PRICE(commodityCode) {
  var API_KEY = 'YOUR_API_KEY'; // Get free at oilpriceapi.com
  var url = 'https://api.oilpriceapi.com/v1/prices/latest?by_code=' + commodityCode;

  var options = {
    'method': 'GET',
    'headers': {
      'Authorization': 'Token ' + API_KEY
    }
  };

  try {
    var response = UrlFetchApp.fetch(url, options);
    var data = JSON.parse(response.getContentText());
    return data.data.price;
  } catch (error) {
    return 'Error: ' + error.message;
  }
}

// Usage: =OIL_PRICE("WTI_USD")  -> Returns: 72.45
// Usage: =OIL_PRICE("BRENT_USD") -> Returns: 76.32

Step 2: Use the function in any cell

Available commodity codes:

WTI_USDBRENT_USDNATURAL_GASDUBAI_USDOPEC_BASKET

Example formulas:

=OIL_PRICE("WTI_USD")
=OIL_PRICE("BRENT_USD")
=OIL_PRICE("NATURAL_GAS")

Get Diesel Prices by State

# Diesel Price Function
function DIESEL_PRICE(stateCode) {
  var API_KEY = 'YOUR_API_KEY';
  var url = 'https://api.oilpriceapi.com/v1/diesel-prices?state=' + stateCode;

  var options = {
    'method': 'GET',
    'headers': {
      'Authorization': 'Token ' + API_KEY
    }
  };

  try {
    var response = UrlFetchApp.fetch(url, options);
    var data = JSON.parse(response.getContentText());
    return data.data.regional_average.price;
  } catch (error) {
    return 'Error: ' + error.message;
  }
}

// Usage: =DIESEL_PRICE("CA") -> Returns: 5.23

Real-World Use Cases

See how professionals use oil price data in Google Sheets

🚚

Fleet Fuel Budgeting

Procurement Manager, Logistics Co.

"We track diesel prices across 12 states where our trucks operate. The spreadsheet auto-updates every morning so I can adjust fuel budgets before dispatch."

# Daily fuel cost estimate
=DIESEL_PRICE("TX") * B2
# B2 = gallons needed
πŸ“Š

WTI-Brent Spread Tracker

Analyst, Energy Trading Desk

"I built a spread calculator that updates every 5 minutes. When WTI-Brent spread exceeds $4, I get an email alert. Saved us from missing arbitrage opportunities."

# Calculate spread
=OIL_PRICE("BRENT_USD")
- OIL_PRICE("WTI_USD")
πŸ“ˆ

Client Price Dashboards

Principal, Energy Consulting

"Each client gets a shared Google Sheet with their relevant commodities. They see live prices without needing Bloomberg access. It's a value-add that keeps them renewing."

# Multi-commodity view
=OIL_PRICE("WTI_USD")
=OIL_PRICE("NATURAL_GAS")
=OIL_PRICE("COAL_USD")

Set Up Auto-Refresh

1Create a refresh function

function refreshPrices() {
  // Force recalculation of all custom functions
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var range = sheet.getDataRange();
  range.setValues(range.getValues());
}

2Set up a time-based trigger

  1. In Apps Script, click the clock icon (Triggers)
  2. Click "+ Add Trigger"
  3. Choose function: refreshPrices
  4. Select event source: "Time-driven"
  5. Select type: "Minutes timer" β†’ "Every 5 minutes"
  6. Click Save

πŸ’‘ Tip: Use "Every hour" instead of "Every 5 minutes" to stay within free tier limits. With 10,000 requests during your 7-day trial, hourly updates give you plenty of flexibility.

Troubleshooting

⚠️"Error: Exception: Request failed"

Your API key is invalid or missing.

Fix: Replace YOUR_API_KEY with your actual API key from the dashboard.

⚠️"#ERROR!" in cell

The custom function isn't recognized.

Fix: Make sure you saved the Apps Script code (Ctrl+S). Try refreshing the spreadsheet.

⚠️"Loading..." stuck forever

Google Sheets is having trouble executing the script.

Fix: Check Apps Script execution log (View β†’ Executions). Look for authorization errorsβ€”you may need to re-authorize.

⚠️Rate limit errors

Too many requests in a short period.

Fix: Reduce refresh frequency or upgrade your plan. Free tier: 10,000 requests during 7-day trial. Consider caching responses.

Complete Function Reference

# All available custom functions
// Basic price lookup
=OIL_PRICE("WTI_USD")           // Returns: 72.45
=OIL_PRICE("BRENT_USD")         // Returns: 76.32
=OIL_PRICE("NATURAL_GAS")       // Returns: 2.89

// Diesel by state
=DIESEL_PRICE("CA")             // Returns: 5.23
=DIESEL_PRICE("TX")             // Returns: 3.12

// With formatting
=TEXT(OIL_PRICE("WTI_USD"),"$0.00")  // Returns: $72.45

// Price change calculations
=OIL_PRICE("WTI_USD") - A1      // Compare to yesterday's close

// Available commodity codes:
// WTI_USD, BRENT_USD, DUBAI_USD, OPEC_BASKET
// NATURAL_GAS, COAL_USD, HEATING_OIL
// GASOLINE_RBOB, JET_FUEL, PROPANE

Crude Oil Codes

  • WTI_USD β€” West Texas Intermediate
  • BRENT_USD β€” Brent Crude (ICE)
  • DUBAI_USD β€” Dubai/Oman
  • OPEC_BASKET β€” OPEC Reference Basket
  • URALS_USD β€” Russian Urals

Other Commodities

  • NATURAL_GAS β€” Henry Hub
  • COAL_USD β€” Newcastle Coal
  • HEATING_OIL β€” NY Harbor
  • GASOLINE_RBOB β€” RBOB Gasoline
  • TTF_EUR β€” Dutch TTF Gas

Frequently Asked Questions

How do I get oil prices in Google Sheets?

Use our Apps Script custom function. Go to Extensions - Apps Script, paste the OIL_PRICE function code, save, then use =OIL_PRICE("WTI_USD") in any cell to get real-time oil prices.

Is the Google Sheets integration free?

Yes! Our free tier includes 7-day free trial with 10,000 requests. For automatic updates, paid plans start at $15/month for 10,000 requests.

What oil prices can I import into Google Sheets?

You can import WTI Crude, Brent Crude, Dubai Crude, OPEC Basket, Natural Gas (Henry Hub), diesel prices by state, and 30+ other commodities.

How often do oil prices update in Google Sheets?

With Apps Script, you can set custom triggers to update every 5 minutes, hourly, or daily. WTI and Brent prices update every 5 minutes during market hours.

Ready to Get Started?

Get your free API key and start using oil prices in Google Sheets today

Get Free API Key