Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8931251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:04:32+00:00 2026-06-15T09:04:32+00:00

I am using vba and I have two sheets one is named Do Not

  • 0

I am using vba and I have two sheets one is named “Do Not Call” and has about 800,000 rows of data in column A. I want to use this data to check column I in the second sheet, named “Sheet1”. If it finds a match I want it to delete the whole row in “Sheet1”. I have tailored the code I have found from a similar question here: Excel formula to Cross reference 2 sheets, remove duplicates from one sheet and ran it but nothing happens. I am not getting any errors but it is not functioning.

Here is the code I am currently trying and have no idea why it is not working

Option Explicit
Sub CleanDupes()
Dim wsA As Worksheet
Dim wsB As Worksheet
Dim keyColA As String

Dim keyColB As String
Dim rngA As Range
Dim rngB As Range
Dim intRowCounterA As Integer
Dim intRowCounterB As Integer
Dim strValueA As String


keyColA = "A"
keyColB = "I"

intRowCounterA = 1
intRowCounterB = 1

Set wsA = Worksheets("Do Not Call")
Set wsB = Worksheets("Sheet1")

Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")

Do While Not IsEmpty(wsA.Range(keyColA & intRowCounterA).Value)
    Set rngA = wsA.Range(keyColA & intRowCounterA)
    strValueA = rngA.Value
    If Not dict.Exists(strValueA) Then
        dict.Add strValueA, 1
    End If
    intRowCounterA = intRowCounterA + 1
Loop

intRowCounterB = 1
Do While Not IsEmpty(wsB.Range(keyColB & intRowCounterB).Value)
    Set rngB = wsB.Range(keyColB & intRowCounterB)
    If dict.Exists(rngB.Value) Then
         wsB.Rows(intRowCounterB).delete
         intRowCounterB = intRowCounterB - 1
    End If
    intRowCounterB = intRowCounterB + 1
Loop
End Sub

I apologize if the above code is not in a code tag. This is my first time posting code online and I have no idea if I did it correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:04:33+00:00Added an answer on June 15, 2026 at 9:04 am

    I’m embarrassed to admit that the code you shared confused me… anyway for the practice I rewrote it using arrays instead of looping through the sheet values:

    Option Explicit
    Sub CleanDupes()
        Dim targetArray, searchArray
        Dim targetRange As Range
        Dim x As Long
    
        'Update these 4 lines if your target and search ranges change
        Dim TargetSheetName As String: TargetSheetName = "Sheet1"
        Dim TargetSheetColumn As String: TargetSheetColumn = "I"
        Dim SearchSheetName As String: SearchSheetName = "Do Not Call"
        Dim SearchSheetColumn As String: SearchSheetColumn = "A"
    
        'Load target array
        With Sheets(TargetSheetName)
            Set targetRange = .Range(.Range(TargetSheetColumn & "1"), _
                    .Range(TargetSheetColumn & Rows.Count).End(xlUp))
            targetArray = targetRange
        End With
        'Load Search Array
        With Sheets(SearchSheetName)
            searchArray = .Range(.Range(SearchSheetColumn & "1"), _
                    .Range(SearchSheetColumn & Rows.Count).End(xlUp))
        End With
    
    
        Dim dict As Object
        Set dict = CreateObject("Scripting.Dictionary")
        'Populate dictionary from search array
        If IsArray(searchArray) Then
            For x = 1 To UBound(searchArray)
                If Not dict.exists(searchArray(x, 1)) Then
                    dict.Add searchArray(x, 1), 1
                End If
            Next
        Else
            If Not dict.exists(searchArray) Then
                dict.Add searchArray, 1
            End If
        End If
    
        'Delete rows with values found in dictionary
        If IsArray(targetArray) Then
            'Step backwards to avoid deleting the wrong rows.
            For x = UBound(targetArray) To 1 Step -1
                If dict.exists(targetArray(x, 1)) Then
                    targetRange.Cells(x).EntireRow.Delete
                End If
            Next
        Else
            If dict.exists(targetArray) Then
                targetRange.EntireRow.Delete
            End If
        End If
    End Sub
    

    Edit: Because it bothered me, I reread the code that you provided. It confuses me because it isn’t written the way I’d have expected and fails unless you’re checking string values only. I’ve added comments to indicate what it’s doing in this snippet:

    'Checks to see if the particular cell is empty.
    Do While Not IsEmpty(wsA.Range(keyColA & intRowCounterA).Value)
        'Stores the cell to a range for no good reason.
        Set rngA = wsA.Range(keyColA & intRowCounterA)
        'Converts the value of the cell to a string because strValueA is a string.
        strValueA = rngA.Value
        'Checks to see if the string is in the dictionary.
        If Not dict.Exists(strValueA) Then
            'Adds the string to the dictionary.
            dict.Add strValueA, 1
        End If
    

    Then later:

     'checks the value, not the value converted to a string.
     If dict.Exists(rngB.Value) Then 
    

    This fails because the Scripting Dictionary does not consider a double to equal a string, even if they would be the same if the double were converted to a string.

    Two ways to fix the code you posted, either change the line I just showed to this:

    If dict.Exists(cstr(rngB.Value)) Then
    

    Or you can change Dim strValueA As String to Dim strValueA.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two worksheets, one which is used to filter the other. Using VBA
I have two excel spreadsheets, one contains data on various persons, while the other
I have an Excel workbook with two sheets: sheet1 has a large table of
I am using VBA to generate SQL queries in Access. I have two SQL
I'm using Excel VBA and have a worksheet_change event like so: Private Sub Worksheet_Change(ByVal
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I am using VBA to check a value of a cell and call an
I m trying to select rows/columns using vba. I want to pass row numbers
I am using Access 2007 for a prototype application.I have a two database testUi.accdb
I have two cells lets say: A1 and A2 The content of each one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.