Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
|
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 16th, 2011, 01:48 PM
Authorized User
 
Join Date: Jun 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Moving between Word Table Rows

Hello,
I am trying to move between word table rows to retrieve data back into the userform, but so far, it's only retrieving one row of record when I click the next button. Here is the code and please tell me what I am doing wrong...
HTML Code:
  Dim i As Integer
    With ActiveDocument.Tables(6)
    For i = 3 To .Rows.Count - 1
        With .Rows(i)
        txtCName.Text = Left(.Cells(1).Range.Text, Len(.Cells(1).Range.Text) - 2)
        txtMembrane.Text = Left(.Cells(2).Range.Text, Len(.Cells(2).Range.Text) - 2)
        txtPore.Text = Left(.Cells(3).Range.Text, Len(.Cells(3).Range.Text) - 2)
        txtFilter.Text = Left(.Cells(4).Range.Text, Len(.Cells(4).Range.Text) - 2)
        txtVendorPure.Text = Left(.Cells(5).Range.Text, Len(.Cells(5).Range.Text) - 2)
        txtVendorNoPure.Text = Left(.Cells(6).Range.Text, Len(.Cells(6).Range.Text) - 2)
        txtMEDIPure.Text = Left(.Cells(7).Range.Text, Len(.Cells(7).Range.Text) - 2)
        End With
    Next i
    End With
Thanks in advance
 
Old August 22nd, 2011, 11:24 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Since you are looping through the rows and assigning the values to the textbox , the textbox gets filled up with the last value at the end

Instead of this statement

For i = 3 To .Rows.Count - 1

You need to pass the actual row you want to take data from

i = iRowIWanted ' This can be a static variable that you can pass from the user form

With .Rows(i)

End With

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
insert listbox items into word table rows bitex Word VBA 1 July 16th, 2011 12:07 PM
Search for listbox item in word table and delete the rows bitex Word VBA 4 July 11th, 2011 09:42 AM
Word doc becomes inactive when moving to a sub RayL Access VBA 0 September 28th, 2010 11:36 AM
Moving rows in Datagrid view control in C# Bob337 General .NET 0 June 9th, 2007 10:13 AM
Moving rows up and Down in Datagrid Baby_programmer ASP.NET 1.0 and 1.1 Professional 5 August 20th, 2006 04:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.