Excel VBA Macro: Delete Rows if Cell Does Not Contain a Certain Text (String) Value

  Рет қаралды 3,501

greggowaffles

greggowaffles

Жыл бұрын

Excel VBA Macro: Delete Rows if Cell Does Not Contain a Certain Text (String) Value
💥Subscribe: / @greggowaffles
Code:
Sub delete_all_rows_without_string()
Dim row_count As Long
Dim i As Long
Dim ws As Worksheet
Dim my_string As String
Set ws = ThisWorkbook.Sheets("Sheet1")
ws.Activate
row_count = ws.Cells(Rows.Count, "A").End(xlUp).Row
i = 1
Do While i <= row_count
my_string = ws.Cells(i, 1).Text
If InStr(my_string, "hostname") = 0 _
And InStr(my_string, "transport output none") = 0 Then
Rows(i).EntireRow.Delete
i = i - 1
row_count = row_count - 1
End If
i = i + 1
Loop
End Sub
#excelmacro #excelvba

Пікірлер: 23
@Jojosmith342
@Jojosmith342 Жыл бұрын
Thank you so much Greg for the valuable tutorial, sharing the code, especially the clear video. Thumb up 👍
@alexrosen8762
@alexrosen8762 Жыл бұрын
You deliver great stuff man 👏💪👏
@greggowaffles
@greggowaffles Жыл бұрын
Thanks 💪😎
@subhash9chack
@subhash9chack 9 ай бұрын
This did my job. Thank you.
@greggowaffles
@greggowaffles 9 ай бұрын
No problem! Happy to hear that.
@Nick_88888
@Nick_88888 Жыл бұрын
Cool, I like it !
@greggowaffles
@greggowaffles Жыл бұрын
Thanks a lot!!
@Nick_88888
@Nick_88888 Жыл бұрын
@@greggowaffles keep them going, learning a lot.
@greggowaffles
@greggowaffles Жыл бұрын
Will do!
@odijin
@odijin Жыл бұрын
Holy moly!!! This is awesome! Thanks very much for sharing your excel skills with this video. I learned a bunch. This video is particular useful for me because it shows how to loop through certain values in cells and than calls for an action. I have a slightly different scenario and wanted to ask your help. I have an excel file with multiple sheets like 100+ sheets, and I want to look for a value in each of those sheets and once that value is identified, is there a way to delete that sheet or sheets altogether? For example, if I used your codes in this video to loop through all the sheets searching for a specified value/string in a call in each of the sheets, then how can I delete all the sheets that contain that value? Thanks for the knowledge!!
@greggowaffles
@greggowaffles Жыл бұрын
Thanks! Would this value be found in any column on any sheet, or are we looking at the same column across all sheets?
@odijin
@odijin Жыл бұрын
@@greggowaffles Thank you for the response. To answer your question, this value would be found in the same column and row in all the sheets. So for example in every sheet if cell A1 has the string "Turtle Soup" then that entire sheet should be deleted, and it loops through all the sheets looking for turtle soup in cell A1 and deletes any sheets containing that value. Hope my explanation helps. And again, thank you so much for your guidance!!!!!
@greggowaffles
@greggowaffles Жыл бұрын
@@odijin thanks for clarifying! I’ll drop a video on that tomorrow!
@odijin
@odijin Жыл бұрын
@@greggowaffles looking forward to your video! much appreciations.
@greggowaffles
@greggowaffles Жыл бұрын
@@odijin done! 😴😴 kzbin.info/www/bejne/jpPKoYWtqJyJeLM
@raeaustin
@raeaustin Жыл бұрын
Is it possible to delete everything that doesn't match cell B1? In the example, hostname would be in B1. If InStr(my_string, "if it matches B1") = 0 _
@judahlee7837
@judahlee7837 Жыл бұрын
Hi Greg, how do I delete rows if cell contains a Certain Time Value???
@nullhas
@nullhas Жыл бұрын
Fantastic Greg. How we can use this to delete rows (if a column contains duplicate email id or mobile number)?
@greggowaffles
@greggowaffles Жыл бұрын
Thanks! Do you have a specific example?
@nullhas
@nullhas Жыл бұрын
@@greggowaffles Yes…let me know how can I share?
@imronnesia5170
@imronnesia5170 8 ай бұрын
worked. but too slow. is there faster way?
Excel VBA Macro: Delete Rows Based on Cell Value (Zeros and Blanks)
5:51
Sigma girl and soap bubbles by Secret Vlog
00:37
Secret Vlog
Рет қаралды 14 МЛН
Excel VBA IF THEN Statement (with ELSEIF & Looping in cells)
12:10
Leila Gharani
Рет қаралды 314 М.
VBA Macro to Delete Rows Based on Cell Values
9:32
Excel Campus - Jon
Рет қаралды 139 М.
VBA to Delete Multiple Columns based on Headers - Excel VBA Macro Example
8:45
How to Get List of File Names in a Folder using Excel
5:40
Excel Weez
Рет қаралды 6 М.
Excel VBA Macro: Delete Rows (Based on List of Values)
12:22
greggowaffles
Рет қаралды 605
Delete Rows based on Value/Text // Excel VBA Tutorial
8:53
Data Nik
Рет қаралды 19 М.
Excel VBA FIND Function (& how to handle if value NOT found)
9:33
Leila Gharani
Рет қаралды 192 М.
Excel VBA Delete Duplicate Rows
9:31
The Excel Cave
Рет қаралды 8 М.
Delete Rows Based On Criteria Excel VBA Macro
6:39
Excel Macro Mania
Рет қаралды 43 М.