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!
 

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Snakehips

Well-known Member
Joined
May 17, 2009
Messages
4,888
Office Version
2013
Platform
Windows
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.
 

dee_ln

New Member
Joined
Feb 9, 2015
Messages
3
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.
 

Snakehips

Well-known Member
Joined
May 17, 2009
Messages
4,888
Office Version
2013
Platform
Windows
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.
 

Forum statistics

Threads
1,089,394
Messages
5,407,990
Members
403,176
Latest member
mehtavish1

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top