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 7051069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:13:11+00:00 2026-05-28T03:13:11+00:00

So based off of a dropdown selection in sheet B , we want to

  • 0

So based off of a dropdown selection in sheet "B", we want to scroll through a bunch of rows in sheet "A", delete all of them that don’t have a Cell(4) = dropDownValue, and then copy that range and paste it into sheet "B". The code below runs but doesn’t do anything.

I can debug and see that the dropDownValue is stored correctly, and also that the Cell(4) seems to get pulled correctly for every row it loops through. Brand new to VBA here, coming from a C# background, so this seems very confusing to me.

Any ideas on how to fix this or what I’m doing wrong?

Sheets("B").Select
Dim dropDownValue As String
dropDownValue = Left(Range("L1").Value, 3)

Dim wantedRange As Range
Dim newRange As Range
Dim cell As Object
Dim i As Integer
Set wantedRange = Sheets("A").Range("E11:E200")
For i = 1 To wantedRange.Rows.Count Step 1
    Dim target As String
    target = wantedRange.Rows(i).Cells(4)
    If Not (target Like dropDownValue) Then
        wantedRange.Rows(i).Delete
    End If
Next i

Sheets("B").Select
Application.CutCopyMode = False
wantedRange.copy
Selection.wantedRange.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
  • 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-05-28T03:13:12+00:00Added an answer on May 28, 2026 at 3:13 am

    My reply is based on what I understood from this line which you mentioned in your post

    delete all of them that don’t have a Cell(4) = dropDownValue

    My First question would be.

    What kind of data do you have in Col E? Numbers or Text?

    If it is text then you can use this code which is very fast. It uses “Autofilter” rather than looping the cells.

    Option Explicit
    
    Sub Sample()
        Dim ws1 As Worksheet, ws2 As Worksheet
        Dim LookupVal As String
        Dim ws1rng As Range, toCopyRange As Range
    
        On Error GoTo Whoa
    
        Application.ScreenUpdating = False
    
        Set ws1 = Sheets("A")
        Set ws2 = Sheets("B")
    
        LookupVal = "<>*" & Left(ws2.Range("L1").Value, 3) & "*"
    
        Set ws1rng = ws1.Range("E11:E200")
    
        ws1.AutoFilterMode = False
    
        With ws1rng
            .AutoFilter Field:=1, Criteria1:=LookupVal, Operator:=xlAnd
            Set toCopyRange = .Offset(1, 0).SpecialCells(xlCellTypeVisible)
        End With
    
        ws1.AutoFilterMode = False
    
        '~~> Will copy the data to Sheet B cell A20
        toCopyRange.Copy ws2.Range("A20")
    
    LetsContinue:
        Application.ScreenUpdating = True
        Exit Sub
    Whoa:
        MsgBox Err.Description
        Resume LetsContinue
    End Sub
    

    And if it is numbers then use this

    Option Explicit
    
    Sub Sample()
        Dim sDropDown As String
        Dim lRowCnt As Long, i As Long
        Dim delRange As Range
    
        On Error GoTo Whoa
    
        Application.ScreenUpdating = False
    
        sDropDown = Left(Sheets("B").Range("L1").Value, 3)
    
       With Sheets("A").Range("E11:E200") '<~~ Modified Reafidy's code :)
            For lRowCnt = .Rows.Count To 1 Step -1
                If (.Rows(lRowCnt).Value Like "*" & sDropDown & "*") Then
                    If delRange Is Nothing Then
                        Set delRange = .Rows(lRowCnt)
                    Else
                        Set delRange = Union(delRange, .Rows(lRowCnt))
                    End If
                End If
            Next lRowCnt
    
            If Not delRange Is Nothing Then
                delRange.Delete
            End If
    
            lRowCnt = Sheets("A").Range("E" & Rows.Count).End(xlUp).Row
    
            '~~> Will copy the data to Sheet B cell A20
            Sheets("A").Range("E11:E" & lRowCnt).Copy Sheets("B").Range("A20")
        End With
    
    LetsContinue:
        Application.ScreenUpdating = True
        Exit Sub
    Whoa:
        MsgBox Err.Description
        Resume LetsContinue
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All my controllers are based off of a BaseController, to share properties between them
I have an iphone app that I built based off a tutorial (for a
Basically i want to be able to dynamically create a temp table based off
i have an asp.net-mvc webpage and i want to show a dropdown list that
I have a table based off Sam's Teach Yourself iOS Development's FlowerViewController , that,
I am starting with an Activity based off of this ShakeActivity and I want
I need to generate windows form fields based off of a text file that
If I have a class that is based off another class, how do I
I'm trying to create a custom class that is based off of an XML
I'm attempting to produced a timestamp based off user's selection. I have a form

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.