Comparing Cell Text Not the Formula Behind the Cell Text

baldbrian

New Member
Joined
Dec 22, 2017
Messages
4
Hi,

I have this macro to look at a cell and if it finds a certain value, copy that row to another sheet. My formula works if there is only Text in the cell and fails if a formula is creating the text in the cell.

Example Data:
Col ACol B
Row 1
Project Num

<tbody>
</tbody>

<tbody>
</tbody>
Project Type

<tbody>
</tbody>
Row 2
PM00049355

<tbody>
</tbody>
Senior Living

<tbody>
</tbody>
Row 3
269591

<tbody>
</tbody>
Residential

<tbody>
</tbody>
Row 4
269588

<tbody>
</tbody>
Residential

<tbody>
</tbody>
Row 5
R000030236

<tbody>
</tbody>
Retail

<tbody>
</tbody>
Row 6
274403

<tbody>
</tbody>
Residential

<tbody>
</tbody>
Row 7
CU00000445

<tbody>
</tbody>
Commercial

<tbody>
</tbody>

<tbody>
</tbody>

<tbody>
</tbody>
Now, with the data above in Column B... There is an underlying formula to figure this out (see below):

Code:
=IF(B2="","",IF(LEFT(B2,2)="PM","Senior Living",IF(LEFT(B2,2)="CP","Commercial",IF(LEFT(B2,1)="R","Retail",IF(LEFT(B2,2)="CU","Commercial","Residential")))))

So, even though you "see" the words Residential, Retail, Commercial, or Senior Living, the cell actually contains the above formula.

The Problem...

If I copy the contents of Column B and then Paste-Special-Values into Column C... my macro code works perfectly to find all Residential rows and copy and paste them into another sheet.

However, if I try to run my macro on Column B, my macro can not find the "Residential" lines...

Here is the code that I can't quite get to see the text in those cells...

Code:
If Range("B" & CStr(LSearchRow)).Text = "Residential" Then

I have also tried using .Value in the place of .Text. How do I get my macro to look for the visual text "Residential"?

Thank you for any help!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Correction to first code sample... should have been looking in Col A, sorry about that.

Code:
[COLOR=#333333]=IF(A2="","",IF(LEFT(A2,2)="PM","Senior Living",IF(LEFT(A2,2)="CP","Commercial",IF(LEFT(A2,1)="R","Retail",IF(LEFT(A2,2)="CU","Commercial","Residential")))))[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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