Need Help: Need VBA Code to Delete rows B5 to specific word for various worksheets.
Thanks
Jesse
Need Help: Need VBA Code to Delete rows B5 to specific word for various worksheets.
Thanks
Jesse
Too less information to understand. Please clarify more what you exactly want the Macro to do?
Cheers!
Deep Dave
Hi, jesse77581,
maybe this shows a way how to proceed:
Ciao,Please Login or Register to view this content.
Holger
Use Code-Tags for showing your code: [code] Your Code here [/code]
Please mark your question Solved if there has been offered a solution that works fine for you
jesse77581
You could try this on a copy of your workbook.
Please Login or Register to view this content.
Last edited by jolivanes; 05-10-2013 at 01:45 AM. Reason: Changed range
This code worked below BUT need to keep the word"Test"
Sub EF921892()
Dim rngFound As Range
Set rngFound = Range("B:B").Find(what:="Test")
If Not rngFound Is Nothing Then
Range(Range("B5"), rngFound).EntireRow.Delete
End If
End Sub
Hi, jesse77581,
please use code-tags when you post a procedure.
This will delete all rows between row 5 and the row above the found word.Please Login or Register to view this content.
Ciao,
Holger
Maybe a mock-up attachment with before and after will help.
How do I add in the code below various worksheets names with the same word "test" that needs to be deleted on those sheets?
Sub EF921892()
Dim rngFound As Range
Set rngFound = Range("B:B").Find(what:="Test")
If Not rngFound Is Nothing Then
Range(Range("B5"), rngFound.Offset(-1, 0)).EntireRow.Delete
End If
End Sub
Thank You Very Much
Jesse
Hi, jesse77581,
please use code-tags when posting procedures.
You are short on explaining what various sheets means: in all sheets or in selected sheets?
Please Login or Register to view this content.
Ciao,Please Login or Register to view this content.
Holger
Holger - Thats exactly what i needed. Thanks im going to try to understand this code.
Jesse
Lets say if i accidentally ran the Macro again, how do i stop it from deleting the rows above B1:B5, leaving the word test? Thanks..
Hi, Jesse,
add a check to the row of the found item like
Ciao,Please Login or Register to view this content.
Holger
got it thanks Holger. Do you recommend any tutorials for learning vba?
Hi, Jesse,
maybe start with looking at http://www.excelforum.com/excel-prog...materials.html.
Ciao,
Holger
Thanks Holger,
One last one, yeah right. I searched all over the web and played with it but no luck. I have three the following words in a row, I want to delete the word other two rows(Test Sample & Test Second Sample) and keep the word test, how do i do that?
Test Sample
Test Second Sample
Test
The code as you have provided it:
Sub EF921892_1a()
Dim rngFound As Range
Dim ws As Worksheet
For Each ws In Worksheets
With ws
Set rngFound = .Range("B:B").Find(what:="Test")
If Not rngFound Is Nothing And rngFound.Row > 5 Then
.Range(.Range("B5"), rngFound.Offset(-1, 0)).EntireRow.Delete
End If
End With
Next ws
End Sub
Thanks, Jesse
Hi, Jesse,
I mentioned it before (and no answer to your quesition should be given unless you act according - at least for the last posting):
Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.
Posting code in [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.
Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
Ciao,
Holger
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks