Deleting rows macro

RichJW

Board Regular
Joined
Jul 7, 2015
Messages
94
Hi,
I moved a working macro from one spreadsheet to another andit has now stopped working. In both spreadsheets, the data is in the same rowsand columns, with the exception of there now being one more column (L).
The data starts on row 5, with the headings on row 4. Theamount of rows differs each time I run the macro.
The macro previously found anything in column A with either “Apples”,“Bananas”, or “Plums” and deleted the entire row. Now it leaves the rows in thespreadsheet but throws up no errors.
Another user helped me with the macro, hence I am strugglingto decipher it.
The part of the macro not working is this…

lastrow =Cells(Rows.Count, 1).End(xlUp).Row
v1 =ActiveSheet.Range(Cells(1, 1), Cells(lastrow, 27)).Value2
bUnion = False
For i = 1 Tolastrow
If v1(i, 1) ="Apples" Or v1(i, 1) = "Bananas" Or v1(i, 1) = "Plums"Then
If bUnionThen
Set r1= Union(r1, Cells(i, 1))
Else
Set r1= Cells(i, 1)
bUnion= True
End If
End If
Next i

Thanks,
Rich
 
The macro you have just posted fails at Dim lr As Long, i As Long

It shows a compile error duplicate declaration in current scope
There is no duplicate declaration withing the code I posted.

If you are getting that message all I can think of is that you actually have merged several codes into the one procedure, or something else unusual.

What you posted in post 9 is not a whole procedure. Can we see the whole lot right from the initial

Sub ... line

to the final


End Sub
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You are good at this, Peter :¬)

I've noticed some rogue code, no doubt left from my previous version. It was this...
Dim bUnion As Boolean
Dim i As Long, lastrow As Long
Dim r1 As Range
Dim v1 As Variant

I've deleted it, then added the ,i As Long back in and it runs beautifully.

Thanks again.
Appreciated as always.
Rich
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,709
Members
449,093
Latest member
Mnur

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