Cannot Find Value with Carriage Return

BrianExcel

Well-known Member
Joined
Apr 21, 2010
Messages
975
I am using the following line of code to search for the specific term "Percent WGKFailure". When I look at the value in the cell itself, there appears to be a carriage return or vbcrlf between "WGK" and "Failure", since it spans two lines.

I search for that specific term using the following:


VBA Code:
    Set fnd = .Cells.Find("Percent WGKFailure", LookIn:=xlValues, LookAt:=xlWhole)

I have tried breaking that code up into multiple iterations, including "Percent WGK" & vbcrlf & "Failure", "Percent WGK" & vbnewline & "Failure", etc.

For some reason the code won't find that term. I would use just the "Percent WGK", but there is another column with that in it that can't be deleted.

Any idea how I can modify that particular line to look for the right combination?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Have you tried
VBA Code:
Set fnd = .Cells.Find("Percent" & Chr(10) & "WGKFailure", LookIn:=xlValues, LookAt:=xlWhole)
OR
VBA Code:
Set fnd = .Cells.Find("Percent" & Chr(13) & "WGKFailure", LookIn:=xlValues, LookAt:=xlWhole)
You may also need to reinsert the leading trailling space in the string
 
Upvote 0
THanks Michael. Unfortunately that didn't work.

Also, just to be clear, the proper spacing would have been:

Set fnd = .Cells.Find("Percent WGK" & Chr(10) & "Failure", LookIn:=xlValues, LookAt:=xlWhole)

(The carriage return is between "WGK" and "Failure".

But even testing your theory with that didnt work. It still didn't find it. I am open to different ways to locate that cell, but there is even another cell with "Failure" in it, so I can't just search for that text and code based on it.
 
Upvote 0
On a copy of your sheet try deleting the Percent WGK part from the cell then see what =CODE(A1) returns after changing the A1 to the cell reference the Percent WGK was in.
 
Upvote 0
It's not a column width issue is it...rather than 2 different lines .....does making the column wider eliminate it ??
You could also remove the carriage return with this formula in a different column
Rich (BB code):
=TRIM(SUBSTITUTE(A1,CHAR(10),"")) OR =TRIM(SUBSTITUTE(A1,CHAR(13),""))
 
Upvote 0
How about
VBA Code:
Set Fnd = .Cells.Find("Percent WGK*Failure", , , xlWhole, , , False, , False)
 
Upvote 0
Still no luck. I guess I'll have to just delete that one manually. And MARK858, the character shows Chr(10) but I dont know why it just won't work.
 
Upvote 0
What about...
VBA Code:
Set Fnd = .Cells.Find("Percent WGK*Failure*", , , xlWhole, , , False, , False)
 
Upvote 0
Something else that might be worth trying is
=CODE(MID(A1,8,1))

Does that come back with 32?
 
Upvote 0
I FINALLY found the problem. There were two spaces in between "Percent" and "WGK". Once I adjust the code for that and used the Chr(10) code it worked fine.

Thanks all!
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,643
Members
449,093
Latest member
Ahmad123098

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