Identical code - 1 will not work

T

Todd Huttenstine

THIS CODE WILL WORK:
Private Sub CommandButton2_Click()
Dim i As Integer
Dim iLastrow As Integer
Dim Collet As String
Dim rng As Range
Dim cl As Object
Dim numcount3 As Long

numcount3 = Application.WorksheetFunction.CountA(Sheets
("Resolutions").Range("AD:AD"))

For Each cell In Sheets("Resolutions").Range("AF2:AF"
& numcount3)

Set Wks = ActiveSheet
Collet = ("AE:AE")
whatwant = cell
iLastrow = Wks.Cells(Rows.Count, Collet).End
(xlUp).Row
For i = iLastrow To 1 Step -1
If Wks.Cells(i, Collet).Value Like
whatwant Then
'Wks.Rows(i).Delete 'this will delete
the entire row
Wks.Rows(i).Resize(, 2).Delete
Shift:=xlShiftUp
End If
Next i
Next cell
End Sub



THIS CODE WILL WORK:
Private Sub CommandButton3_Click()
Dim i As Integer
Dim iLastrow As Integer
Dim Collet As String
Dim rng As Range
Dim cl As Object
Dim numcount3 As Long

numcount3 = Application.WorksheetFunction.CountA(Sheets
("Resolutions").Range("A:A"))

For Each cell In Sheets("Resolutions").Range("C2:C" &
numcount3)

Set Wks = ActiveSheet
Collet = ("B:B")
whatwant = cell
iLastrow = Wks.Cells(Rows.Count, Collet).End
(xlUp).Row
For i = iLastrow To 1 Step -1
If Wks.Cells(i, Collet).Value Like
whatwant Then
'Wks.Rows(i).Delete 'this will delete
the entire row
Wks.Rows(i).Resize(, 2).Delete
Shift:=xlShiftUp
End If
Next i
Next cell
End Sub

The only difference in the 2 is that the code that will
not work is positioned furthur down the worksheet. The
data is the exact same as well.


Whats wrong here?

Todd Huttenstine
 
T

Todd Htutenstine

Well it runs and I see the hours glass but then when the
hour glass goes away, nothing has happened to the data. I
dont understand why it works on the one range of data but
not on the other range.
 
K

kkknie

Without getting into it too much, I would suggest adding som
Debug.Print statements to your code to see what some of your variable
turn out to be. It will also let you know what's going on in yo
code.

If you've never used them before, just put debug.print "Here" somewher
and run the code. When it gets there the word Here will show up in th
immediate pane of the VB Editor.

More appropriate examples would be

Debug.Print numcount3
Debug.Print iLastRow

to see what your variables are doing. It could be that the code is no
working because it is not running.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top