Selection/Table & Text

B

Benz

Hi,

I've been trying all sorts of things to get this to work.... and again I
find myself posting here. Im trying to have it so the when I launch this
userform it knows what table (theres multiple tables in the doc) cell&Row ,
then it copies the cell text from the same row but 2 columns to the left and
places that text in Textbox1 of the user form. Below is what i have so far,
ive tried everything! And would appreciate any help. Thank you in advance.

Addy = "& Chr(64 + Selection.Cells(1).ColumnIndex-1) &
Selection.Cells(1).RowIndex"
TextBox1.Text = Addy.Text

Ben Z.
 
J

Jean-Guy Marcil

Benz was telling us:
Benz nous racontait que :
Hi,

I've been trying all sorts of things to get this to work.... and
again I find myself posting here. Im trying to have it so the when I
launch this userform it knows what table (theres multiple tables in
the doc) cell&Row , then it copies the cell text from the same row
but 2 columns to the left and places that text in Textbox1 of the
user form. Below is what i have so far, ive tried everything! And
would appreciate any help. Thank you in advance.

Addy = "& Chr(64 + Selection.Cells(1).ColumnIndex-1) &
Selection.Cells(1).RowIndex"
TextBox1.Text = Addy.Text

Here's an example sub. For this example, all you need is a form with a
textbox called "txtFromCell" and a close button.

'_______________________________________
Option Explicit
'_______________________________________
Sub Test()

Dim myForm As frmTest
Dim strCellText As String

If Not Selection.Information(wdWithInTable) Then
MsgBox "You must place the cursor in a table"
Exit Sub
End If


With Selection
'remove cell marker from cell text
strCellText = Left(.Cells(1).Range.Text, Len(.Cells(1).Range.Text) - 2)
If .Cells(1).ColumnIndex <= 2 Then
'If cursor in column one or two, cannot copy two columns to the left
MsgBox "Cannot copy the text as current column index is too small."
Else
'Copy text two cells to the left
.Tables(1).Cell(.Cells(1).RowIndex, _
.Cells(1).ColumnIndex - 2).Range.Text = strCellText
End If
End With

Set myForm = New frmTest
Load myForm

With myForm
.txtFromCell.Text = strCellText
.Show
'Do what you have to do with the form here...
'You only need a button on the form with Me.Hide
'If you need a cancel button write back.

End With

Unload myForm

Set myForm = Nothing

End Sub
'_______________________________________

Depending on the content of the text in the cell, you may need to tweak the
string before putting it in the userform textbox.

--

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