Test if cell contains certain text, text that contains parentheses.

dee_ln

New Member
Joined
Feb 9, 2015
Messages
3
Hi all,

I have a sheet like this (sorry about all the borders):


(Nobody) (0)

<tbody>
</tbody>

sometext

<tbody>
</tbody>

Steve Smith (888)

<tbody>
</tbody>

attribute 1

<tbody>
</tbody>

Jane Smith (787)

<tbody>
</tbody>

sometext

<tbody>
</tbody>

(Nobody) (0)

<tbody>
</tbody>

sometext

<tbody>
</tbody>

<tbody>
</tbody>


In VBA, I need to copy the rows that do not contain “(Nobody) (0)” to another sheet.

EXAMPLE1:
If Worksheets("Sheet1").Cells(i, 1).Value <> "(Nobody) (0)" Then
Worksheets("Sheet1").Rows(i).EntireRow.Copy Destination:=Worksheets("Sheet3").Range("A" & rowcounter)
Etc.

EXAMPLE2:
If Worksheets("Sheet1").Cells(i, 1).Value <> "Steve Smith (888)" Then
Worksheets("Sheet1").Rows(i).EntireRow.Copy Destination:=Worksheets("Sheet3").Range("A" & rowcounter)
Etc.

Example 1 does not work, it does not recognize the value (Nobody) (0) in a cell. It copies all rows.
Example 2 does work, it copies all rows that do not contain Steve Smith (888) in a cell.

I need example 1 to work, So I guess the code needs extra quotes or something around (Nobody) (0)

Any suggestions would be greatly appreciated!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
dee_in,

Welcome top Mr Excel.

If your cells contain the string '(Nobody) (0) then I can see no reason why Example 1 should not work.

Do you have leading or trailing spaces or any other 'invisible' control characters in with that string?
Do a test formula on the string cell e.g. if string is in A1.... =LEN(A1) and see if the answer is 12.
 
Upvote 0
Hi. Thank you for answering.
Indeed the cells seem to contain some invisible characters as evidenced by the LEN test.

This data was imported from a Sharepoint export.
I'll have to find an other way to test. The sheet contains more columns, so I'll try testing on those.

Thanks.
 
Upvote 0
Try incorporating something like below in order to clean up the cells(i,1) data before testing.

Rich (BB code):
'EXAMPLE1:


With Worksheets("Sheet1").Cells(i, 1)
' remove any trailing and leading spaces and invisible control characters
.Value = Evaluate("SUBSTITUTE(TRIM(CLEAN(" & .Address & ")),CHAR(160),"""")")
If .Value <> "(Nobody) (0)" Then
Worksheets("Sheet1").Rows(i).EntireRow.Copy Destination:=Worksheets("Sheet3").Range("A" & rowcounter)
'Etc.
End If
End With

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,600
Members
449,038
Latest member
Arbind kumar

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