Macro to copy text from text box to table.

J

John

I currently have a document with two tables containing a series of text
boxes. The text boxes
are linked via a macro such that when a user clicks on a command button the
input
from a text box in one table is copied to a second box in the second table
further down the page.

The macro so far uses the following code;

Private Sub CommandButton1_Click()

TextBox1.SelStart = 0
TextBox1.SelLength = TextBox1.TextLength
TextBox1.Copy

TextBox2.SelStart = 0

TextBox2.Paste
TextBox1.SelStart = 0

End Sub


Private Sub TextBox1_Change()
TextBox2.Text = TextBox1.Text
End Sub


The users currently pick and choose which pieces of text they wish to
move to the second box however as the macro moves the text to a
specific box, if we do not pick all of the items the second table is left
with gaps
which is less than ideal.

Hence is there any way that I can make the macro copy the text from the
selected box to the
next available cell or row in the second table rather than to a specified
text box?
 
G

Greg

John,

Just an example. The following macro paste to the first empty cell it
encounters in table(2)

Sub PasteToCell()
Dim oCell As Cell
For Each oCell In ActiveDocument.Tables(2).Range.Cells
If Len(oCell.Range) = 2 Then
Selection.Paste
End If
Next
End Sub
 
G

Greg

John,

Corrrection. The following should paste the clipboard contents to the
next empty cell:

Sub PasteToCell()
Dim oCell As Cell
For Each oCell In ActiveDocument.Tables(2).Range.Cells
If Len(oCell.Range) = 2 Then
oCell.Range.Paste
Exit For
End If
Next
End Sub
 
J

John

Greg,

Thanks for that, i will give it a try now and see of that solves my problem.

John
 

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