Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-17-2022, 03:12 AM
WJSwanepoel WJSwanepoel is offline Add text at beginning of cells in Word table Windows 10 Add text at beginning of cells in Word table Office 2021
Advanced Beginner
Add text at beginning of cells in Word table
 
Join Date: Dec 2019
Location: Krugersdorp, South Africa
Posts: 65
WJSwanepoel is on a distinguished road
Question Add text at beginning of cells in Word table

How can I add a text string at the beginning of each of the lefthand cells in a table?



Lets say the cell contains "1:2" I wish to add "Gen. " so that it reads "Gen. 1:2"

The start of every lefthand cell must be set to "Gen. "
Reply With Quote
  #2  
Old 08-17-2022, 04:32 AM
gmaxey gmaxey is offline Add text at beginning of cells in Word table Windows 10 Add text at beginning of cells in Word table Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oTbl As Table
Dim oCell As Cell
  Set oTbl = Selection.Tables(1)
  For Each oCell In oTbl.Range.Cells
    If oCell.ColumnIndex = 1 Then
      If Len(oCell.Range.Text) > 2 Then
        oCell.Range.InsertBefore "Gen "
      End If
    End If
  Next
lbl_Exit:
  Exit Sub
End Sub
Sub ScratchMacro2()
'A basic Word macro coded by Greg Maxey
Dim oTbl As Table
Dim oCol As Column
Dim oCell As Cell
  Set oTbl = Selection.Tables(1)
  If oTbl.Uniform Then
    Set oCol = oTbl.Columns(1)
    For Each oCell In oCol.Cells
      If oCell.ColumnIndex = 1 Then
        If Len(oCell.Range.Text) > 2 Then
          oCell.Range.InsertBefore "Gen "
        End If
      End If
    Next
  End If
lbl_Exit:
  Exit Sub
End Sub

If the table is uniform, the second macro will be faster.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 08-17-2022, 05:11 AM
WJSwanepoel WJSwanepoel is offline Add text at beginning of cells in Word table Windows 10 Add text at beginning of cells in Word table Office 2021
Advanced Beginner
Add text at beginning of cells in Word table
 
Join Date: Dec 2019
Location: Krugersdorp, South Africa
Posts: 65
WJSwanepoel is on a distinguished road
Default

Thank you!
Reply With Quote
Reply

Tags
cell, table, word 365



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add text at beginning of cells in Word table Converting table to text (and back) with carriage returns in cells, split and merged cells ndajko Word 5 11-04-2019 07:53 AM
Add text at beginning of cells in Word table Word macro to insert text at the beginning of paragraph but skip tables ashalles135 Word VBA 5 09-26-2018 09:49 AM
Add text at beginning of cells in Word table word macro To insert text at the beginning and at end of paragraph ArieH Word VBA 20 09-10-2017 04:23 PM
Add text at beginning of cells in Word table Text position in merged table cells - word 2010 ellentk Word Tables 3 09-09-2015 03:33 PM
Add text at beginning of cells in Word table Add text to the beginning/ending of each line in word ballmoney Word 1 01-17-2010 02:19 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft