Macro to find a value, select the row and delete it

fabriciofcmiranda

Board Regular
Joined
Jun 27, 2006
Messages
62
I have a big code that has a part that is supposed to look for the range value on a column, find it, select the whole row and delete it. But I just can't put it to work. This is the part of the code, considering rng as Range and "budget_code" as the part of column A where the macro needs to look for the value:

Code:
      Sheets("budget").Select
      Range("budget_code").Find(What:="rng.Value", After:=ActiveCell, LookIn:= _
         xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
         xlNext, MatchCase:=False, SearchFormat:=False).Activate
      rng.EntireRow.Delete

I'd appreciate if someone could help me on this one.

Thanks a lot!
 
I fixed the problem and now the code is working on the original workbook. But it keeps choking sometimes. From my understading, it chokes whenever the cells next to the code (on the same row that will be deleted) are empty. Since I don't understand what the criterias of the "Find" really mean (LookIn, LookAt, SearchOrder, etc.), I'd like to ask for help to check whether all the criteria are really right on this code:

Code:
Set rngFound = Range("budgetprojetos_codigo").Find(What:=rng.Value, After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)

I don't know if it's relevant, but the code has this format: 00.00.00 (where 0 could be any number from 0 to 9).

Thank you very much for the help!!!
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Can anyone help me with this one? I've been stuck on this same problem for over 2 weeks... I really need to understand why the macro works perfectly some times and chokes on other times... I'm sure the problem is on the "Find" statement... Thanks a lot in advance!
 
Upvote 0
loozablake, thank you so much for your help through e-mail! I just wanted to share here the solution:

The new code should be:

Code:
      Sheets("Budget Projects").Select
      Set rngFound = Range("budgetprojects_code").Find(What:=rng.Value, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
      rngFound.EntireRow.Delete

The problem was on the "After:=ActiveCell" part of the code, that looked for something on a range that could be wrong. I also changed the "LookIn:=xlFormulas" for "LookIn:=xlValues", since I'm looking for value and not a formula.

Once more, thank you so much, loozablake, for your help.

Best regards,
FM
 
Upvote 0

Forum statistics

Threads
1,216,038
Messages
6,128,450
Members
449,453
Latest member
jayeshw

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