Text String Compare

rainmantwo

New Member
Joined
Jun 13, 2002
Messages
45
Is there any way to compare the first 5 characters of ce;l a2 with the frist frive chararcters of c2 and then write a true of false?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Simply use:

=Left(A2,5)=Left(C2,5)

It will return TRUE or FALSE
 
Upvote 0
Can I add a delete to this

if the charatcers in c2 match the ones in a2 can you delete the c2 contents?

Thanks that was quick
 
Upvote 0
Now with an Excel formula. Excel formulas cannot delete values in other cells. You would need to use VBA to do that, i.e.

Code:
If Left(Range("A2"),5)=Left(Range("C2"),5) Then Range("C2").ClearContents
 
Upvote 0
Thanks for the help !! But...

Thanks,

It seemes to work fine in row 2 but I need the marco to look at all the rows.. sometimes 8,000.

Thanks again
 
Upvote 0
Then you need to write a loop to loop through the range, i.e.

Code:
Dim i as Long
For i = 2 to 8000
   If Left(Cells(i,"A"),5)=Left(Cells(i,"C"),5) Then Cells(i,"C").ClearContents
Next i

Edited to fix code.
 
Upvote 0
sorry, new to vb I do not know how to write a loop through
???
I wrote it for you in my previous post...
 
Upvote 0
Then you need to write a loop to loop through the range, i.e.

Code:
Dim i as Long
For i = 2 to 8000
   If Left(Cells(i,"A"),5)=Left(Cells(i,"C"),5) Then Cells(i,"C").ClearContents
End If

You didn't close the loop:
Code:
Dim i as Long
For i = 2 to 8000
   If Left(Cells(i,"A"),5)=Left(Cells(i,"C"),5) Then Cells(i,"C").ClearContents
Next
 
Upvote 0
My apologies, you are correct BJungheim.

I meant to type in "Next i" instead of "End If". I went back and re-editing the code.

I guess that is what I get for trying to write code at 11:00 PM when I should be in bed!
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,028
Members
448,940
Latest member
mdusw

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