![]() |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
![]()
Hello,
the following code in VBA should move a selected text, from one cell to the adjacent cell to its right, after selecting the ENTER key. I tried it, but it doesn't work. Am I wrong or missing something? I don't have to move the contents of a cell, just what is selected in a cell. Example: in a table cell, I have this sentence: Check inserted files. I would like that, by selecting inserted files and pressing the ENTER key, the two selected words were moved to the adjacent cell on the right. To run the code, I insert this into the VB page with the Develop menu (ALT+F11). Here is the code: Sub MoveTextInTable() Dim oTable As Table Dim oCell as cell Dim oSelection as a selection Set oSelection = Application.Selection If oSelection.Information(wdWithInTable) = True then Set oTable = oSelection.Tables(1) Set oCell = oSelection.Cells(1) If not oCell.Next is nothing then ' Check if next cell exists oCell.Range.Cut oCell.Next.Range.InsertBefore Selection.Text Else MsgBox "Cannot move text to the right, as there is no adjacent cell." End If Else MsgBox "Select a cell within a table." End If End sub Carlo - Italy |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
wrdy | Word | 4 | 05-18-2022 12:25 AM |
![]() |
mbcohn | Word VBA | 35 | 04-13-2021 11:40 AM |
extract time from a cell and move it to front of cell before text | ewso | Excel | 20 | 03-19-2017 11:34 AM |
![]() |
Shinaj | Excel | 2 | 05-01-2014 01:50 PM |
Auto-populate an MS Word table cell with text from a diff cell? | dreamrthts | Word Tables | 0 | 03-20-2009 01:49 PM |