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
Apps Script
Custom functions that auto-update with triggers
- βFull automation
- βCustom refresh intervals
- βComplete control
- ~5-min setup
Google Add-on
Install from marketplace, configure in sidebar
- βOne-click install
- βNo coding
- βAuto-refresh built in
- ~$15/mo (paid plans)
Get Crude Oil Prices
Step 1: Open Apps Script Editor
- In Google Sheets, click Extensions - Apps Script
- Delete any existing code
- Paste the code below and save
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.32Step 2: Use the function in any cell
Available commodity codes:
WTI_USDBRENT_USDNATURAL_GASDUBAI_USDOPEC_BASKETExample formulas:
Get Diesel Prices by State
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.23Alabama
Formula: =DIESEL_PRICE("AL")
View prices
Alaska
Formula: =DIESEL_PRICE("AK")
View prices
Arizona
Formula: =DIESEL_PRICE("AZ")
View prices
Arkansas
Formula: =DIESEL_PRICE("AR")
View prices
California
Formula: =DIESEL_PRICE("CA")
View prices
Colorado
Formula: =DIESEL_PRICE("CO")
View prices
Connecticut
Formula: =DIESEL_PRICE("CT")
View prices
Delaware
Formula: =DIESEL_PRICE("DE")
View prices
Florida
Formula: =DIESEL_PRICE("FL")
View prices
Georgia
Formula: =DIESEL_PRICE("GA")
View prices
Hawaii
Formula: =DIESEL_PRICE("HI")
View prices
Idaho
Formula: =DIESEL_PRICE("ID")
View prices
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."
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."
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."
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
- In Apps Script, click the clock icon (Triggers)
- Click "+ Add Trigger"
- Choose function:
refreshPrices - Select event source: "Time-driven"
- Select type: "Minutes timer" β "Every 5 minutes"
- 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
// 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, PROPANECrude Oil Codes
WTI_USDβ West Texas IntermediateBRENT_USDβ Brent Crude (ICE)DUBAI_USDβ Dubai/OmanOPEC_BASKETβ OPEC Reference BasketURALS_USDβ Russian Urals
Other Commodities
NATURAL_GASβ Henry HubCOAL_USDβ Newcastle CoalHEATING_OILβ NY HarborGASOLINE_RBOBβ RBOB GasolineTTF_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