Something wrong with this code.

BenNV

Board Regular
Joined
Mar 27, 2002
Messages
160
I have the following piece of code, which I was hoping would delete any lines when matched with any other string in Column 1.

Sub Del_Entries()

Dim Store_Ins As String

Set FixWS = Workbooks("test.xls").Worksheets("ion")

rr = 1

Store_Ins = Cells(rr, 1).Value

rr = rr + 1

While (FixWS.Cells(rr, 1).Value <> "")
If (FixWS.Cells(rr, 1).Value = Store_Ins) Then
FixWS.Cells(rr, 1).EntireRow.Delete Shift:=xlShiftUp
Else
Store_Ins = Cells(rr, 1).Value
End If
rr = rr + 1
Wend

End Sub



So, here's some data to work with:

RRR/OOO 07/05/02
RRR/OOO 07/05/02
RRR/OOO 07/05/02
RRR/OOO 07/05/02
FFF/MMM 07/05/02
FFF/MMM 07/05/02
FFF/MMM 07/05/02
FFF/MMM 07/05/02
RRR/OOO 07/05/02
RRR/OOO 07/05/02
RRR/OOO 07/05/02
RRR/OOO 07/05/02
RRR/OOO 07/05/02
RRR/OOO 07/05/02
RRR/OOO 07/05/02
XXX/WWW 07/05/02
XXX/WWW 07/05/02
XXX/WWW 07/05/02
XXX/WWW 07/05/02
XXX/WWW 07/05/02
XXX/WWW 07/05/02



This should only leave RRR/OOO, FFF/MMM, XXX/WWW and their relative date.

For some reason it doesn't perform the task in one go, I have to run it a few times. Can you help?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I've "fixed" your code, sort of, but there is an error in your loop. This loop only compares for identical values that are in continuous rows, so the result is:

RRR/OOO 07/05/02
FFF/MMM 07/05/02
RRR/OOO 07/05/02
XXX/WWW 07/05/02


Here is the modified code:

<pre>
Sub Del_Entries()

Dim Store_Ins As String

Set FixWS = Workbooks("test.xls").Worksheets("ion")

rr = 1

Store_Ins = Cells(rr, 1).Value

rr = rr + 1

While (FixWS.Cells(rr, 1).Value <> "")
If (FixWS.Cells(rr, 1).Value = Store_Ins) Then
FixWS.Cells(rr, 1).EntireRow.Delete Shift:=xlShiftUp
Else
rr = rr + 1
Store_Ins = Cells(rr, 1).Value
End If
Wend

End Sub</pre>

You can mess about with it to get it to do what you want, or if you want a suggestion, just repost.

HTH :biggrin:
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,312
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top