Fi69
asked on
Word vba code to return the position of the cell I'm in
Hi experts
I suspect this is probably simple, but I have no idea how to do it, or go about it.
I've selected a particular table and I want to find particular text in there. Then I want to go to that text and return the value of the cell I'm in, for example Row(4), Cell(2).
Can someone tell me how to do this.
I suspect this is probably simple, but I have no idea how to do it, or go about it.
I've selected a particular table and I want to find particular text in there. Then I want to go to that text and return the value of the cell I'm in, for example Row(4), Cell(2).
Can someone tell me how to do this.
Dim myrange As Range
set myrange = ActiveDocument.Tables(2).Range
myrange.Find.Execute findtext:=texta
If myrange.Find.Found = True Then
'goto that text. What cell am I in?
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
use :
dim myCell as cell
SET myCell = ActiveDocument.Tables(2).C ell(" & myrange.Cells(1).RowIndex & ", " & myrange.Cells(1).ColumnInd ex & ")
myCell.select
dim myCell as cell
SET myCell = ActiveDocument.Tables(2).C
myCell.select
ASKER
it errors on this line
SET myCell = ActiveDocument.Tables(2).C ell(" & myrange.Cells(1).RowIndex & ", " & myrange.Cells(1).ColumnInd ex & ")
SET myCell = ActiveDocument.Tables(2).C
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dim myrange As Range
Set myrange = ActiveDocument.Tables(2).R ange
myrange.Find.Execute findtext:=texta
If myrange.Find.Found = True Then
myrange.Cells(1).Select
End If
Set myrange = ActiveDocument.Tables(2).R
myrange.Find.Execute findtext:=texta
If myrange.Find.Found = True Then
myrange.Cells(1).Select
End If
ASKER
That worked - gosh I frustrate myself. Thanks Graham!
ASKER
Exactly what I was looking for.
As dotoffice has illustrated above, if you only want to select the cell, you don't need to know the address.
ASKER
Yes, that is a much more simple way of doing what I've ended up doing. Sorry dotoffice I already awarded points. Thanks for your help! I ended up changing what I originally set out to do.
ASKER
Thank you the message box tells me what cell I need correctly. That's fantastic.
Sorry, novice here, having trouble selecting that cell. Do you know what I'm doing wrong?
Dim myCell as 'I can't get anything to work'
myCell = ActiveDocument.Tables(2).C
myCell.range.Select