Consulting

Results 1 to 3 of 3

Thread: Adding Text to the end of a cell in a table

  1. #1

    Adding Text to the end of a cell in a table

    Good Morning all

    I'm racking my brain here and I know the answer must be simple but I'm definitely missing something.

    Essentially what I would like to do is to move to a specific cell in a table and add selected text at the end of whatever text is already written in there.

    For example If Cell(4,2) had "ID, Company Name" written in it I would then like to update it to "ID, Company Name, Industry"

    The code I have at the moment is as follows:

    If CheckBox6.Value = True Then
    ActiveDocument.Tables(1).Cell(4, 2).Select
    Selection.MoveRight Count:=-1
    Selection.TypeText Text:=", Industry"

    I have tried variations of moveright & moveend as well as count being -1,0,1 and yet they all seem to still not be coming up correctly, either putting data into the previous cell (4,1) or deleting the text that is already in the cell and replacing it with the new text.

    Any advice on this would be greatly appreciated.

    Regards

    William

  2. #2
    This is easy to handle if you use ranges

    Dim oCell As Range 'declare a range
    Set oCell = ActiveDocument.Tables(1).Cell(4, 2).Range 'set the range to the cell in question
    oCell.End = oCell.End - 1 'omit the cell end character from the range
    oCell.Collapse 0 'collapse the range to its end
    oCell.Text = ", Industry" 'enter the range text
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Absolutely perfect! Thank you very much for that. I need to do more study / learning on declaring ranges I think.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •