need VBA Selecting cells Containing specific Characters

pisdukas

New Member
Joined
Jun 12, 2019
Messages
7
Hello, Forum,

I am unable to find a VBA which would select cells which contain specific characters in a range. Could some give a hand?


Thank you for taking the time.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Welcome to the Board!

Can you be a little more specific?
Maybe provide an actual example of exactly what you are trying to do (and why the built-in "Find" functionality in Excel won't work?)
 
Upvote 0
I want to delete rows which contains value "WHI", I have highlighted it.

You can try this one
Rich (BB code):
Sub DeleteRowss()
'
' DeleteRowss Macro
'


'
    Sheets("Sheet1").Select


    ActiveSheet.Range("A1").AutoFilter Field:=1, Criteria1:="*WHI*", Operator:=xlFilterValues
    
    Range("A1").Select
    ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
    
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Delete Shift:=xlUp
    
    Worksheets("sheet1").AutoFilterMode = False


End Sub


Put your sheet name where it says sheet 1
 
Last edited:
Upvote 0
You can try this one
Rich (BB code):
Sub DeleteRowss()
'
' DeleteRowss Macro
'


'
    Sheets("Sheet1").Select


    ActiveSheet.Range("A1").AutoFilter Field:=1, Criteria1:="*WHI*", Operator:=xlFilterValues
    
    Range("A1").Select
    ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
    
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Delete Shift:=xlUp
    
    Worksheets("sheet1").AutoFilterMode = False


End Sub


Put your sheet name where it says sheet 1

Thanks for the reply, for some reason it doesnt work​





 
Upvote 0
Thanks for the reply, for some reason it doesnt work​

Go to the code in vba and have your excel sheet open, put your cursor inside the vba code some where, press f8 to step through the code 1 line at a time and watch it work. Then let me know where you have the error and what is the error message

if the error is referencing a line then copy and paste that line back here

or you can send me a copy of your data and I can fix the code to work on it.

The code worked for me in the test file you sent, it deleted all the rows where the A cell contained WHI
 
Last edited:
Upvote 0
Go to the code in vba and have your excel sheet open, put your cursor inside the vba code some where, press f8 to step through the code 1 line at a time and watch it work. Then let me know where you have the error and what is the error message

if the error is referencing a line then copy and paste that line back here

or you can send me a copy of your data and I can fix the code to work on it.

The code worked for me in the test file you sent, it deleted all the rows where the A cell contained WHI

I just found out a mistake of mine. All of the cells Containing "WHI" has an ending "..WHI-S", "...WHI-M", "...WHI-L" etc. Exept one type of cells containig "WHI" has no additional ending. And I need to keep those cells. Here is another smaple I attached. The red color cells with "WHI" should remain, and yellow color should be deleted. Is it possible do that?

https://rokastestas.s3.eu-west-3.amazonaws.com/sample2.xlsm
 
Upvote 0
I just found out a mistake of mine. All of the cells Containing "WHI" has an ending "..WHI-S", "...WHI-M", "...WHI-L" etc. Exept one type of cells containig "WHI" has no additional ending. And I need to keep those cells. Here is another smaple I attached. The red color cells with "WHI" should remain, and yellow color should be deleted. Is it possible do that?

https://rokastestas.s3.eu-west-3.amazonaws.com/sample2.xlsm

:confused: Please explain why Rows 18, 34 and 50 (just to name a small few) should be deleted when they contain just WHI at the end.
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,226
Members
452,620
Latest member
dsubash

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