cell text

D

Drake

Hi. I am trying to write code that will look at the text in a particular
cell of a table.

So far, I have:

Set rcell = ActiveDocument.Tables(3).Cell(2, 4).range
if rcell.text = "test1"
msgbox "Answer1"
elseif rcell.text = "text2"
msgbox "Answer2"
end if

My problem is that it isn't seeing the text. If I do an Immediate on it, it
throws this symbol -  on the next line. So it comes back with:
test1


Any thoughts?
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Drake > écrivait :
In this message, < Drake > wrote:

|| Hi. I am trying to write code that will look at the text in a particular
|| cell of a table.
||
|| So far, I have:
||
|| Set rcell = ActiveDocument.Tables(3).Cell(2, 4).range
|| if rcell.text = "test1"
|| msgbox "Answer1"
|| elseif rcell.text = "text2"
|| msgbox "Answer2"
|| end if
||
|| My problem is that it isn't seeing the text. If I do an Immediate on it,
it
|| throws this symbol -  on the next line. So it comes back with:
|| test1
|| 
||

Those  are from the End of cell marker (¤).
Although it is a single symbol on the page, Word looks at it as if it were
indeed one character, but VB string manipulations count it as two
characters.
This modified code removes the ¤ from the string when comparing.

'_______________________________________
Dim rcell As Range

Set rcell = ActiveDocument.Tables(1).Cell(2, 2).Range

With rcell
If Left(.Text, Len(.Text) - 2) = "Test1" Then
MsgBox "Answer1"
ElseIf Left(.Text, Len(.Text) - 2) = "Test2" Then
MsgBox "Answer2"
End If
End With
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
D

Drake

Bonjour Jean-Guy,

I have an additional question regarding this matter. An added piece came
up....

continuing on with the example below, "test1" may end up being "test1/a" or
"test1/b" or "test1/c", etc. How do I code to allow for that? In reality,
test1 is actually text that is varying in length and content. I am using
"test1" to be simple. In actuality, it would be more like "dog/a" or
"horse/b" or "octopus/a" or "lizard/j", etc.

Hope this makes sense.....

Drake
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Drake > écrivait :
In this message said:
Bonjour Jean-Guy,

I have an additional question regarding this matter. An added piece came
up....

continuing on with the example below, "test1" may end up being "test1/a" or
"test1/b" or "test1/c", etc. How do I code to allow for that? In reality,
test1 is actually text that is varying in length and content. I am using
"test1" to be simple. In actuality, it would be more like "dog/a" or
"horse/b" or "octopus/a" or "lizard/j", etc.

Hope this makes sense.....

Hmm, I am not sure it does... I do not see the problem.. Why can't you use:

'_______________________________________
Dim rcell As Range

Set rcell = ActiveDocument.Tables(1).Cell(2, 2).Range

With rcell
If Left(.Text, Len(.Text) - 2) = "lizard/a" Then
MsgBox "Answer1"
ElseIf Left(.Text, Len(.Text) - 2) = "lizard/b" Then
MsgBox "Answer2"
End If
End With
'_______________________________________


Maybe you have to describe your situation a bit more thoroughly. What is the
logic test you want to apply?
What is the content of each cell?
Where are you going with this?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Drake > écrivait :
In this message said:
Jean-Guy,

I realize my error. You have been of tremendous assistance.

Thanks!

Glad you sorted it out... I am not sure I helped... but if you say I did,
then you're welcome!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top