Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-10-2017, 06:55 PM
Amitti Amitti is offline How can I compare a string in a cell to another string? Windows 10 How can I compare a string in a cell to another string? Office 2010 32bit
Novice
How can I compare a string in a cell to another string?
 
Join Date: Mar 2017
Posts: 7
Amitti is on a distinguished road
Default How can I compare a string in a cell to another string?

Hi All,

This may be a silly question but I'm really stuck and need your help.

I'm trying to compare a string in a cell to another string to see if they match but can't seem to be able to because the comparison always fails. I must be using the wrong call. Like this:




'assume i and str are declared
With ActiveDocument
str = .Tables(i).Cell(2, 1).Range.Text
Select Case str
Case "AAA"
'do something
Case "BBB"
'do something
End Select
End With

I also tried Left(str, len(str) -1) to try and get rid of the non-printable character at the end of the string in the cell but it didn't work for me either.
Is there an easy way to compare a string in a cell to another string?

Thank you in advance.
Reply With Quote
  #2  
Old 04-10-2017, 07:29 PM
macropod's Avatar
macropod macropod is offline How can I compare a string in a cell to another string? Windows 7 64bit How can I compare a string in a cell to another string? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
str = Split(.Tables(i).Cell(2, 1).Range.Text, vbCr)(0)

As for 'Left(str, len(str) - 1)', you'd need to use 'Left(str, len(str) - 2)', since cells are terminated by a Chr(7) & Chr(13) pair.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-10-2017, 07:35 PM
Amitti Amitti is offline How can I compare a string in a cell to another string? Windows 10 How can I compare a string in a cell to another string? Office 2010 32bit
Novice
How can I compare a string in a cell to another string?
 
Join Date: Mar 2017
Posts: 7
Amitti is on a distinguished road
Default

Thank you! it works like a charm.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find all string within string. PRA007 Word VBA 18 02-12-2016 08:11 PM
How can I compare a string in a cell to another string? Rule: Look for this number string and only this number string kcm5153 Outlook 3 03-30-2015 10:15 PM
How can I compare a string in a cell to another string? Text in string projectpupil7 Excel 7 11-23-2014 12:03 AM
How can I compare a string in a cell to another string? Way to search for a string in text file, pull out everything until another string? omahadivision Excel Programming 12 11-23-2013 12:10 PM
How can I compare a string in a cell to another string? using a cell content as a string with COUNTIF geoffm Excel 1 08-16-2011 11:31 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:54 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft