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
My reply is based on what I understood from this line which you mentioned in your post
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.
And if it is numbers then use this