---
title: Using In-Cell Formulas to run SOQL queries in XL-Connector
description: How to run SOQL queries in Salesforce to populate a single cell in your spreadsheet using a formula.
---

[Skip to content](https://knowledge.xappex.com/using-in-cell-formulas-to-run-soql-queries-in-xl-connector#main-content)

English

Show submenu for translations

![Xappex-logo-with-name.png\]](https://knowledge.xappex.com/hs-fs/hubfs/Xappex-logo-with-name.png?height=40&name=Xappex-logo-with-name.png)

- [Products](https://knowledge.xappex.com/using-in-cell-formulas-to-run-soql-queries-in-xl-connector#products)
- [Blog](https://knowledge.xappex.com/using-in-cell-formulas-to-run-soql-queries-in-xl-connector#blog)
- [About](https://knowledge.xappex.com/using-in-cell-formulas-to-run-soql-queries-in-xl-connector#about)

Open main navigation

Close main navigation

- [Products](https://knowledge.xappex.com/using-in-cell-formulas-to-run-soql-queries-in-xl-connector#products)
- [Blog](https://knowledge.xappex.com/using-in-cell-formulas-to-run-soql-queries-in-xl-connector#blog)
- [About](https://knowledge.xappex.com/using-in-cell-formulas-to-run-soql-queries-in-xl-connector#about)
- English
  
  Show submenu for translations
- Go to xappex.com

 Go to xappex.com

 Hello. How can we help you?

- There are no suggestions because the search field is empty.

1. [Xappex Knowledge Base](https://knowledge.xappex.com/?hsLang=en)
2. [I use Microsoft Excel](https://knowledge.xappex.com/i-use-microsoft-excel?hsLang=en)
3. [I use XL-Connector](https://knowledge.xappex.com/i-use-microsoft-excel?hsLang=en#i-use-xl-connector)

# Using In-Cell Formulas to run SOQL queries in XL-Connector

## How to run SOQL queries in Salesforce to populate a single cell in your spreadsheet using a formula.

In this article we wanted to show you a little VBA trick that will help you run SOQL queries in Salesforce to populate a single cell in your spreadsheet using a formula that looks as follows:

=RUNQUERY(“SELECT id FROM opportunity WHERE name ='”&B1&”‘”)

In order to achieve this, you’ll need to create a custom formula in your VBA editor as follows:

1. Click on Developer -\> Script Editor in Excel
2. Create the following function in VBA editor:
   
   ```
   Public Function RUNQUERY(query As String)   Dim addin As Office.COMAddIn   Dim automationObject As Object   Set automationObject = Application.COMAddIns("TaralexLLC.SalesforceEnabler").Object   ar = automationObject.RetrieveData(query, False, False, errorText)   If Not errorText = Empty Then      RUNQUERY = errorText   Else      If UBound(ar, 2) > 0 Then         RUNQUERY = ar(0, 1)      Else         RUNQUERY = ""      End If   End IfEnd Function
   ```

Now you can use this custom formula run any SOQL query for a single cell. Please, keep in mind that only the value in the first row of the first column will be returned as the result of this formula.

If a query is written correctly, you should see something like the following in the cell:

![](https://www.xappex.com/wp-content/uploads/2017/11/CustomFormula.png)

Now if you want this macro to appear in all documents that you open on this computer click on File -\> Save As and save the document as an Excel Add-In:

![](https://www.xappex.com/wp-content/uploads/2017/11/saveAsAddin.png)

- [I use Google Sheets](https://knowledge.xappex.com/i-use-google-sheets?hsLang=en)
- [I use Microsoft Excel](https://knowledge.xappex.com/i-use-microsoft-excel?hsLang=en#main-content)

    - [FAQs](https://knowledge.xappex.com/i-use-microsoft-excel?hsLang=en#faqs)
    - [I use XL-Connector](https://knowledge.xappex.com/i-use-microsoft-excel?hsLang=en#i-use-xl-connector)
    - [I use XL-Connector 365](https://knowledge.xappex.com/i-use-microsoft-excel?hsLang=en#i-use-xl-connector-365)
    - [I use Excel Merge package](https://knowledge.xappex.com/i-use-microsoft-excel?hsLang=en#i-use-excel-merge-package)
- [I use Looker Studio](https://knowledge.xappex.com/i-use-looker-studio?hsLang=en)

- [Products](https://knowledge.xappex.com/using-in-cell-formulas-to-run-soql-queries-in-xl-connector#products)
- [Blog](https://knowledge.xappex.com/using-in-cell-formulas-to-run-soql-queries-in-xl-connector#blog)
- [About](https://knowledge.xappex.com/using-in-cell-formulas-to-run-soql-queries-in-xl-connector#about)

[![Chill listening crop-3](https://knowledge.xappex.com/hubfs/Xappex-Logo.svg "Chill listening crop-3")](https://www.xappex.com)

xappex.com Help Center

Copyright © 2026, Xappex LLC