Delete Rows Based on a Cell Value (or Condition) in Excel [With and Without VBA]

Managing data efficiently in Excel often means removing unwanted rows that meet certain criteria—such as rows with specific text, dates, numbers, or even partial matches. Whether you’re cleaning up a small spreadsheet or preparing a large dataset for analysis, understanding how to delete rows based on cell values will help you keep your data tidy and relevant. This guide explores multiple techniques to remove rows in Excel according to specific cell values, making your data management tasks faster and more accurate regardless of your proficiency with Excel features or VBA automation.

This tutorial explains several methods to remove rows from an Excel worksheet based on the value in a specific cell or according to set conditions.

Here are four different approaches you can use to delete rows depending on their cell values:

  1. Using Filters:
    Apply a filter to your data, select the criteria you want to remove (for example, rows where “Status” is “Inactive”), and delete all the filtered rows at once.
  2. Sorting Data:
    Sort your data by the column you want to filter (e.g., sort by “Department” so all “Sales” records are grouped together) and then delete all the matching rows in one go.
  3. Finding Cells with Specific Values:
    Use Excel’s “Find” feature to locate cells with a value like “Expired”, select those rows, and delete them all together.
  4. VBA Automation:
    Automate row deletion by using a VBA macro that filters and deletes based on your criteria (e.g., remove all rows where “Order Status” is “Cancelled”).

Tip:
Choose the method that best fits your dataset’s structure and your workflow. Remember, deleting a row removes everything in that row—including all data to the left and right. If you only want to clear certain cells but keep the row and other information, consider using the filter and dummy column trick, or manually clearing cell contents instead of deleting the row.

Wildcard Matching Example:
With Find and Replace, you can use wildcards for powerful matching. For instance, to find every region ending with “East” (such as “North-East” or “South-East”), type “*-East” (the asterisk stands for any sequence of characters).

Example VBA Codes

Delete All Rows Where “Status” is “Inactive”:

textSub DeleteRowsWhereInactive()
    ActiveCell.AutoFilter Field:=3, Criteria1:="Inactive" 'Assumes the Status column is column 3
    ActiveSheet.AutoFilter.Range.Offset(1, 0).Rows.SpecialCells(xlCellTypeVisible).Delete
End Sub

Prompt User before Deleting Rows Where “Order Status” is “Cancelled” Without Deleting the Entire Row:

textSub DeleteCancelledStatusCells()
    Dim MsgboxAns As Integer
    ActiveCell.AutoFilter Field:=4, Criteria1:="Cancelled" 'Assumes Order Status is column 4
    MsgboxAns = MsgBox("Are you sure you want to delete these cells?", vbYesNo + vbQuestion)
    If MsgboxAns = vbYes Then
        ActiveSheet.AutoFilter.Range.Offset(1, 0).Rows.SpecialCells(xlCellTypeVisible).Delete (xlShiftUp)
    End If
End Sub

Delete Rows in an Excel Table Where “Department” is “Support”:

textSub DeleteRowsinTableForDepartment()
    Dim Tbl As ListObject
    Set Tbl = ActiveSheet.ListObjects(1)
    ActiveCell.AutoFilter Field:=2, Criteria1:="Support" 'Assumes Department is column 2
    Tbl.DataBodyRange.SpecialCells(xlCellTypeVisible).Delete
End Sub

**#Excel #ExcelTips #A #ExcelTutorial

Let me know if you need more tailored code or examples for your data!

Cross Selling Matrix Deep Dive – Power BI & DAX Tutorial (Market Basket)

Understanding the Cross Selling Matrix in Power BI

A cross selling matrix is a powerful visualization used in sales analytics to identify which products are often purchased together by the same customers over a selected period. This form of basket analysis helps businesses uncover cross-selling opportunities, promotional ideas, boost revenue, and optimize product strategy.

The video demonstrates not just the process of creating a cross selling matrix in Power BI, but dives deep into the crucial concepts of DAX, context transition, and relationship management needed to generate accurate, actionable insights.

Key Steps and Concepts

1. Foundational Understanding: Context in Power BI & DAX

  • Context determines how your formulas and visuals behave. The row and column headers of your matrix create unique contexts for every cell, impacting which data is aggregated or filtered.
  • Proper understanding of context ensures your DAX calculations are returning meaningful results for each product pairing in the matrix.

2. Core Calculation: Customers Who Purchased Both Products

  • The goal is to find out, for any intersection in the matrix, how many customers bought Product A (row) AND Product B (column) within the selected date range.
  • This is done by creating two tables:
  • Table 1: All customers who bought Product A.
  • Table 2: All customers who bought Product B.
  • The INTERSECT function is then used to find customers common to both tables.
  • The final result is a COUNTROWS(INTERSECT(…)), revealing the number of unique customers who purchased both products.

3. DAX Techniques Used

  • VALUES(): Used to dynamically return a list of customers filtered by the current context (product, time frame, etc.).
  • CALCULATETABLE(): Allows creation of virtual tables filtered by specific product or comparison product context.
  • TREATAS(): Establishes virtual relationships between tables where no direct relationship exists, vital for comparing separate product lists.
  • ALL() or ALLEXCEPT(): Used to remove or adjust existing model relationships temporarily, isolating the proper comparison across products for accurate results.

4. Supporting Table for Comparison

  • To evaluate pairwise cross-selling (row vs column), a comparison products table is created, usually replicating your products dimension but used solely for comparison logic.
  • This table is not physically related to the sales table, so relationships are built on-the-fly in DAX using TREATAS.

5. Dynamic Filtering and Analysis

  • The entire technique is dynamic, meaning selecting different dates or filters in your Power BI report instantly recalculates the matrix.
  • This adaptability makes the matrix valuable for both exploratory analytics and operational dashboards.

Why Build a Cross Selling Matrix?

  • Reveal Product Affinities: Quickly see which items are often bought together, ideal for bundle promotions and recommendations.
  • Drive Sales Strategies: Identify which products could benefit from cross-promotion or upselling.
  • Customer Insight: Understand multi-product purchasing behavior within your customer base.

Example DAX Pattern for Purchased Both Products

Purchased Both Products = 
VAR Customers_ProductA =
    VALUES(Sales[CustomerID]) // For current row product context
VAR Customers_ProductB =
    CALCULATETABLE(
        VALUES(Sales[CustomerID]),
        TREATAS(VALUES('Comparison Products'[ProductID]), Sales[ProductID])
    )
RETURN
    COUNTROWS(INTERSECT(Customers_ProductA, Customers_ProductB))
  • Replace column/table names as per your own model.
  • Adjust context and relationships as necessary for your specific data schema.

Takeaway

By mastering this advanced cross selling matrix technique and the supporting DAX concepts (like context, table functions, and virtual relationships), you empower yourself to unlock powerful, nuanced insights into customer behavior and product performance using Power BI.

If you’re keen to further enhance your skills on this, Enterprise DNA is a superb resource! Check them out and watch their video on this below! 🙂


[1] https://www.youtube.com/watch?v=iZJz30LSik4

Cross Selling Matrix Deep Dive – Power BI & DAX Tutorial

In this tutorial we cover how to create a cross selling matrix.

This requires a full understanding of the concept of ‘context’ and much more.

Some advanced DAX formulas are covered in detail, especially table functions.

Plenty of great techniques to learn about during this one.

Enjoy!

Sam

***** Learning Power BI? *****

FREE COURSE – Ultimate Beginners Guide To Power BI – http://bit.ly/2SGof6C

FREE COURSE – Ultimate Beginners Guide To DAX – http://bit.ly/2AyEb3P

FREE – Power BI Resources – http://bit.ly/2C2aBn3

FREE – 60 Page DAX Reference Guide Download – http://bit.ly/2AyEc7T

Learn more about Enterprise DNA – http://bit.ly/2RacRD3

Enterprise DNA Membership – http://bit.ly/2AAqa5u

View on YouTube

Formula.Firewall Error in Power Query & Power BI: Rebuild This Data Combination Solved (MSPTDA 9.5)

Learn how to deal with Power Query Error: Formula.Firewall: Query references other queries or steps, so it may not directly access a data source. Please rebuild this data combination. Two solutions are presented in this video.
Download Files: Excel Start: https://ift.tt/2L7OwpO
Zipped Folder: https://ift.tt/2PShOvY
Download Excel FINISHED Files: https://ift.tt/2MsL7Hs
Download pdf Notes about Power Query: https://ift.tt/2wkNW2K
Assigned Homework – these are problems for you to practice your new M Code skills:
Download Excel File with Homework: https://ift.tt/2MmtxFf
Example of Finished Homework: https://ift.tt/2L7OxtS

Chris Webb’s blog about this topic: https://ift.tt/2NATkG3
Ken Puls blog about this topic: https://ift.tt/2PShRb8

Comprehensive Microsoft Power Tools for Data Analysis Class, BI 348, taught by Mike Girvin, Excel MVP and Highline College Professor.

View on YouTube

excel vlookup tutorial for beginners to advanced with examples

VLOOKUP Function Beginner to Advanced With Examples: How To Use Excel VLOOKUP Function

What is VLOOKUP and why it matters

The Excel VLOOKUP function searches for a value in the first column of a table and returns a value from a specified column in the same row, which makes it perfect for pricing lookups, HR rosters, invoices, commissions, and taxonomy maps across large datasets without manual searching. VLOOKUP’s syntax is =VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup]) where the lookup value must be in the leftmost column of the table array, the return column is selected by index, and the final argument controls exact vs. approximate matching.

Exact match VLOOKUP for clean lookups

For unique identifiers like IDs, SKUs, or emails, use exact match with FALSE (or 0) to return only precise matches and avoid unexpected results, which is the most common production pattern in business workbooks. A typical formula is =VLOOKUP(E2, $A$2:$C$11, 2, FALSE), with the table range locked using absolute references so it copies reliably down a column while the lookup reference remains relative for each row.

Approximate match VLOOKUP for bands and tiers

Approximate match is ideal for tax brackets, commission tiers, shipping rates, or grade scales, where the first column is sorted ascending and Excel returns the closest value less than or equal to the lookup value when an exact match doesn’t exist. When the last argument is TRUE or omitted, VLOOKUP returns the next smaller match in a sorted table, which is essential for continuous ranges like “income-to-tax-rate” or “sales-to-commission” bands.

Preventing errors with IFERROR and best practices

Production-grade sheets guard against #N/A and related issues by wrapping VLOOKUP in IFERROR to show a clean message or blank when a value is missing, and by using data validation lists to eliminate typos at the source of the lookup value. Following best practices like locking the table with $A$2:$D$100, ensuring the lookup key sits in the leftmost column, and documenting whether a formula is exact or approximate match will make your workbooks resilient and easier to maintain.

Cross-sheet and cross-workbook references

VLOOKUP works seamlessly across sheets and files by including sheet names (Sheet2!$A$2:$D$100) or external workbook paths in the table_array, which enables central lookup catalogs, shared master data, and distributed models while preserving consistent references via absolute ranges. When linking to closed workbooks, Excel embeds the file path in the reference, so keeping related files together and stable is important for long-term reliability.

Dynamic col_index_num with MATCH

Hard-coding the column index makes models brittle; pairing VLOOKUP with MATCH on the header row creates a dynamic column index that automatically adapts when columns are moved or new fields are inserted. For example, =VLOOKUP($E2, $A$2:$Z$100, MATCH($G$1, $A$1:$Z$1, 0), FALSE) uses the header text in G1 to return the correct column even if the schema changes, which is a best-in-class pattern for durable reports.

Horizontal and vertical record retrieval

Full-record retrieval can be automated horizontally with COLUMNS and vertically with ROWS to pull multiple adjacent fields from a single VLOOKUP key without manual indexing, which is useful for summary views, profile cards, and line items. Using expandable ranges with COLUMNS(B8:B8)+1 for horizontal sequences or ROWS(B22:B22)+1 for vertical sequences produces 1, 2, 3 indices as formulas copy, keeping the sheet tidy and dynamic.

Multi-criteria VLOOKUP strategies

VLOOKUP returns the first match and can’t natively filter duplicates, so multi-criteria lookups are solved by creating a helper “join key” column (e.g., =A2&”|”&B2) and using the same join in the lookup value, which creates a unique, leftmost key VLOOKUP can read. If schema changes are not allowed, an advanced alternative uses CHOOSE inside VLOOKUP to construct a two-column virtual table in-memory, enabling multi-field keys without altering the source range, which is powerful for protected or external datasets..

Partial text lookups and text-number mismatches

Real data often requires extracting part of a code to perform a lookup, where LEFT/RIGHT/MID combined with SEARCH finds variable-length segments like prefixes before a dash, or three-character mids after a delimiter, creating consistent keys to match against the table. When numbers are stored as text (or vice versa), coercing with +0 or VALUE ensures reliable matching, and using TRIM removes hidden spaces that can otherwise cause #N/A even when values look identical on screen.

VLOOKUP limitations and when to use alternatives

VLOOKUP only looks to the right, is case-insensitive, and returns only the first match, which can be restrictive in analytics and deduping workflows, especially in wide tables where column order changes over time. More flexible patterns include INDEX/MATCH for left-lookups or returning nth matches, and modern functions like XLOOKUP that support bidirectional lookup, exact/approximate logic, default values, and built-in error handling with a cleaner syntax for both beginners and power users.

VLOOKUP examples you can copy

Basic exact match (best for IDs, SKUs)
=VLOOKUP(E2, $A$2:$D$100, 3, FALSE) returns the value from the 3rd column where A matches E2 in a locked table range for safe copying.

Approximate match for tiers (sorted ascending)
=VLOOKUP(E2, $A$2:$C$20, 2, TRUE) returns the banded rate or amount when E2 falls between thresholds in the first column, which must be ascending.

Dynamic column with MATCH
=VLOOKUP($E2, $A$2:$Z$100, MATCH($G$1, $A$1:$Z$1, 0), FALSE) adapts to column moves by resolving the column index from header text in G1.

Multi-criteria with helper join
=VLOOKUP($H2&”|”&$I2, $A$2:$E$100, 5, FALSE) matches two inputs by concatenating them to a unique leftmost key (e.g., Name|State).

CHOOSE-based two-key (no schema change)
=VLOOKUP($H2&”|”&$I2, CHOOSE({1,2}, $A$2:$A$100&”|”&$B$2:$B$100, $E$2:$E$100), 2, FALSE) builds a virtual two-column table for a composite key without adding a helper column.

Partial text before a dash
=VLOOKUP(LEFT(E2, SEARCH(“-“, E2)-1), $A$2:$C$100, 2, FALSE) extracts the left segment as the key when source IDs contain a prefix-delimiter pattern.

Coercing text numbers
=VLOOKUP(VALUE(MID(E2, SEARCH(“-“, E2)+1, 3)), $A$2:$C$100, 2, FALSE) converts a three-digit middle segment to a number for consistent matching.

Trim hidden spaces reliably
=VLOOKUP(TRIM(E2), $A$2:$D$100, 3, FALSE) cleans errant whitespace in the lookup value; if spaces are in the table’s first column, apply TRIM to that column or reconstruct a trimmed array pattern where appropriate.

Pro tips for learning

Beginners should start with exact matches on clean tables and practice absolute references, then add IFERROR to handle missing keys gracefully, and use data validation to reduce typos in lookup cells during entry, which mirrors enterprise data hygiene. Intermediate and advanced users benefit from MATCH-driven column selection, helper columns for multi-key joins, CHOOSE-based virtual tables when schemas are locked, and partial text extraction patterns that mirror real-world IDs from CRMs, ERPs, and finance systems

keywords: excel vlookup tutorial for beginners to advanced with examples, vlookup help, vlookup.

Other resources to help you:

  1. https://www.ablebits.com/office-addins-blog/excel-vlookup-tutorial/
  2. https://support.microsoft.com/en-us/office/vlookup-function-0bbc8083-26fe-4963-8ab8-93a18ad188a1
  3. https://www.excel-easy.com/examples/vlookup.html
  4. https://www.goskills.com/Excel/Resources/VLOOKUP-exact-match-approximate-match
  5. https://www.w3schools.com/excel/excel_vlookup.php
  6. https://www.youtube.com/watch?v=-hJxIMBbmZY
  7. https://www.extendoffice.com/documents/excel/6393-excel-vlookup-function.html
  8. https://www.youtube.com/watch?v=DZEPA9UhLBw
  9. https://www.semrush.com/blog/how-to-choose-long-tail-keywords/
  10. https://www.youtube.com/watch?v=xIynD1gFOLo
  11. https://www.ablebits.com/office-addins-blog/vlookup-formula-examples/
  12. https://www.youtube.com/watch?v=v5l82vjuMpY
  13. https://www.youtube.com/playlist?list=PL856071E833250503
  14. https://www.youtube.com/watch?v=w0KQ5ByxELo
  15. https://www.reddit.com/r/excel/comments/16szzbc/teach_me_vlookup_in_excel/
  16. https://www.youtube.com/watch?v=zqFE6uIJ65s
  17. https://www.youtube.com/watch?v=ck9MR95MtZg
  18. https://www.youtube.com/watch?v=ZGKpXh426Ko
  19. https://www.youtube.com/user/ExcelIsFun
  20. https://www.youtube.com/watch?v=-1BDpwCxyug
  21. https://www.youtube.com/watch?v=d3BYVQ6xIE4
code execution vba

Code Execution Has Been Interrupted- VBA Keeps Breaking – Solved!

How to stop code execution has been interrupted error in Excel VBA.

My Excel VBA Keeps Breaking: A “code execution has been interrupted” keeps coming up, but my Code is Not “Broken”

It’s 2025 and this is still happening, so I just have to share this handy trick.  Sometimes when I’m running VBA code in Excel, it starts getting wonky.  The Break/Debug window keeps popping up during execution, for no good reason.  Code execution has been interrupted, over and over.    The code has run perfectly fine in the past, perhaps hundreds of times.  It’s almost as if something is stuck and hanging in the background.  Restarting Excel does no good.  It seems that the VBA interface itself needs a reset, but clicking reset does nothing.  It’s quite frustrating.

There is a Solution!!

code execution has been interrupted window

When you receive the code execution has been interrupted pop-up,  click Debug.

Then press Ctrl+Pause/Break twice.

Click on the Green Arrow or press F5 to resume.

You should be good to go, as long as there is nothing inherently wrong with your VBA code!

I’m not sure how or why this works,but it does. I think there may be some sort of bug in Excel, so hopefully it will be fixed at some point.  I hope this helps you as much as it has helped me!  Simple solutions sure are the best!

Comment below and let me know if there are other issues you would like me to solve!

Save

Top 5 Copy Paste Functions in Excel – Values, Formatting, Special and More!

Top 5 Copy Paste Functions in Excel – A Detailed Guide

The copy and paste functions in Excel save time and effort, since there’s no need to retype information that already exists.  In  this post,  I will cover and explain the different copy and paste operations that Excel offers.

There are a million reasons under the sun to copy and paste in Excel.  You may want to duplicate information in one column, another sheet or even another workbook.  Perhaps you are copying and pasting data from another source, such as MS Access, your web browser, or a PDF document.  Maybe you are moving data around within a worksheet or workbook.

Copy vs. Cut in Excel

When you select copy within Excel, you are telling the program that you would like to duplicate the information.

When you choose cut in Excel, you remove the data from where it currently exists, and place it elsewhere.

How to Copy

To begin, you must select the data that you would like to copy.  This will move the source data to the clipboard, which is a temporary holding place in the background.

Highlight the data.  To copy using the mouse, right click, and select the copy option.   You may also use the keyboard shortcut – Ctrl + c.  Click in the destination cell.

Paste Options Explained

Copy Paste Special
Copy Paste Menu in Excel

PastePaste – If you would like to paste your data as is, with no changes, right click and select this icon.

Excel ValuesPaste Values – If you’re copying a formula, but only want to paste the results, select this icon, with the numbers.

Excel Paste Formulas Paste Formula – Say you wanted to paste just a formula or set of formulas, you would choose the option with the “fx” in the icon.  Note that depending on what the formula is doing, the result may be different from the original.

Excel Transpose PastePaste and Transpose – The transpose option allows you to change the orientation of your data.  Let’s say you had four items listed vertically.  Using the transpose option would allow you to paste the items horizontally, or vice versa.

Excel Formatting PastePaste Formatting – Excel gives you the option of pasting the formatting only.  If you had some nice shading, or conditional formatting and wanted to copy that, but not modify the formula or data of the target cell or range, then paste formatting would be the option to choose.

Excel Link PastePaste Link – You can simply paste a link to, or reference to the source as a formula or formulas if you are copying multiple cells.  Hint: If you are copying only one cell, by default, the reference will be absolute.  This means that you can move the formula around, but the cell(s) it is pointing to will not change.  When copying multiple cells, the result will be relative references.

 

Save

Save

Save

Save

Save