IMPORTRANGE to Import Visible Rows in Google Sheets

Published on

The IMPORTRANGE function in Google Sheets does not have an argument that allows you to directly import only the visible rows from one Google Sheets file to another. However, with a workaround, it is possible to import visible rows using IMPORTRANGE.

Before proceeding with the workaround, keep in mind that you need edit access to modify the source file.

Why Do We Require Edit Access?

Edit access is necessary because the workaround involves adding an extra column (a helper column) with a formula in the source file. Without edit access, you cannot modify the source file to include the helper column.

Once the helper column is set up, you can use the QUERY function combined with IMPORTRANGE to import only the visible rows in Google Sheets.

What Are Hidden Rows?

In the context of this tutorial, hidden rows include:

  • Rows hidden using the “Hide row” command in the right-click menu.
  • Collapsed row groups (using the “Group rows” command in the right-click menu or the View menu).
  • Rows filtered out using the “Filter” option in the Data menu.
  • Rows filtered out using Slicer
Note: Filtering with a Slicer doesn’t work with the IMPORTRANGE-QUERY combo to import visible rows. This may be a bug requiring developer attention.

How to Import Only Visible Rows Using IMPORTRANGE in Google Sheets

Let’s start with the source file settings. As mentioned earlier, we will be adding a helper column in the source file.

Sample Data to Import (Tab name: ‘kvp1’):

Sample Data for Importing

Source File Side – Helper Column Settings

  1. Make all the rows visible (as shown in my sample data above).
  2. The last column containing data in my sheet is column D, so we will use column E as the helper column. In cell E1, insert the following formula:
=MAP(A1:A8, LAMBDA(r, SUBTOTAL(103, r)))
  1. Hide the rows you want to (for example, I am hiding rows 3, 4, and 5).

Can You Explain the Formula in Use?

We use SUBTOTAL(103, A1) to return 1 when the row is visible and 0 when it is hidden.

To apply this formula to every row in the range, we convert it into a lambda function as follows:

LAMBDA(r, SUBTOTAL(103, r))

We apply this lambda function to each row in the range A1:A8 using the MAP function, which returns an array of 1s for visible rows and 0s for hidden rows.

It will return 1 for visible rows and 0 for hidden rows. Ensure that the range used in the MAP function is not empty to correctly identify the hidden rows.

Destination File Side – QUERY IMPORTRANGE Formula to Import Visible Rows

Imported All Rows:

To import all rows from the source file, follow these steps:

  1. Copy the URL of the source file from your browser’s address bar and paste it into cell A1 of the destination file.
  2. In cell A2, enter the range (be sure to include the helper column), such as kvp1!A1:E8. You can later adjust the rows and columns as needed.
  3. Use the IMPORTRANGE formula in cell A3:
=IMPORTRANGE(A1, A2)

You may be prompted to click “Allow Access” to import the data.

IMPORTRANGE to Import All Rows in Google Sheets

Import Visible Rows:

To import only the visible rows, we need to specify a condition. Unfortunately, IMPORTRANGE does not have an argument for conditional imports.

However, we can use the QUERY function with the IMPORTRANGE data to filter the rows based on the helper column. Modify the formula in A3 as follows:

=QUERY(IMPORTRANGE(A1, A2), "SELECT Col1, Col2, Col3, Col4 WHERE Col5 = 1")

This will import only the visible rows where the value in column E (the helper column) is 1.

IMPORTRANGE to Import Visible Rows in Google Sheets

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

How to Extract Numbers from Text in Excel with Regex

You can use the REGEXEXTRACT or REGEXREPLACE functions to easily extract numbers from text...

Using OFFSET and MATCH Together in Google Sheets: Advanced Tips

One powerful and flexible way to look up values is by combining the OFFSET...

How to Use OFFSET and XMATCH Functions Together in Excel

We often use the OFFSET and XMATCH functions together to match a value in...

How to Calculate Maximum Drawdown in Excel and Google Sheets

You can use the following dynamic array formula to calculate maximum drawdown (MDD) in...

More like this

Using OFFSET and MATCH Together in Google Sheets: Advanced Tips

One powerful and flexible way to look up values is by combining the OFFSET...

Running Count with Structured References in Google Sheets

Running a count with structured references is achievable in Google Sheets tables using the...

Running Total with Structured Table References in Google Sheets

You can use two types of formulas to create a running total with structured...

4 COMMENTS

    • Thanks for pointing that out! You’re right—Slicers currently don’t work with the IMPORTRANGE-QUERY combo. I’ll update the post to reflect this limitation. Appreciate your feedback!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.