CVR lookups in Google Sheets

A small Apps Script gives you a =CVR() formula in Google Sheets that pulls name, city, industry and more straight from the Danish CVR register.

Create the formula

  1. Open your spreadsheet and choose Extensions > Apps Script.
  2. Delete the contents of Code.gs and paste the script below.
  3. Save the project. The formula is now available in the sheet.
javascript
/**
 * Henter et felt fra CVR-registret.
 * Eksempel: =CVR(A2; "name")
 *
 * @param {number} cvr CVR-nummer (8 cifre)
 * @param {string} field Feltnavn, fx "name", "city" eller "industrydesc"
 * @customfunction
 */
function CVR(cvr, field) {
  const cache = CacheService.getScriptCache();
  const key = "cvr_" + cvr;
  let json = cache.get(key);

  if (!json) {
    const res = UrlFetchApp.fetch("https://apicvr.dk/api/v1/" + cvr, { muteHttpExceptions: true });
    if (res.getResponseCode() === 404) return "Ikke fundet";
    if (res.getResponseCode() !== 200) return "Fejl " + res.getResponseCode();
    json = res.getContentText();
    cache.put(key, json, 21600); // 6 timer
  }

  const company = JSON.parse(json);
  const value = company[field || "name"];
  return Array.isArray(value) ? value.map(v => v.name).join(", ") : value;
}

Use the formula

With the CVR number in A2, you can write:

If your spreadsheet uses Danish locale settings, separate the arguments with a semicolon: =CVR(A2; "name").

The script caches responses for 6 hours with CacheService, so several columns with the same CVR number only make one request.

Search by name

Add this function to get a list of hits with CVR number, name and industry. The result spills over several rows and columns.

javascript
/**
 * Søger virksomheder på navn og returnerer CVR-nummer og navn.
 * Eksempel: =CVRSOEG("novo nordisk")
 * @customfunction
 */
function CVRSOEG(name) {
  const url = "https://apicvr.dk/api/v1/search/fuzzy/" + encodeURIComponent(name);
  const hits = JSON.parse(UrlFetchApp.fetch(url).getContentText());
  return hits.slice(0, 10).map(h => [h.cvr_number, h.name, h.industrytext]);
}
Always check protected before using the data for marketing. When it's true, the company has opted out of direct marketing.

Frequently asked questions

Why does the cell say "Ikke fundet"?

That means not found: the CVR number isn't in the register. Check that it has 8 digits and isn't formatted as a number with thousands separators.

Is there a limit on how many rows I can look up?

Google limits how many URL fetches a script can make per day. The cache helps, but spread very large lists over several days.