Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-14-2021, 10:35 AM
Steve Kunkel Steve Kunkel is offline Want to Insert Column and add text into entire column. Windows 10 Want to Insert Column and add text into entire column. Office 2019
Advanced Beginner
Want to Insert Column and add text into entire column.
 
Join Date: May 2019
Location: Seattle area
Posts: 77
Steve Kunkel is on a distinguished road
Default Want to Insert Column and add text into entire column.

Hi Folks,
Given an existing table in Word, I'd like to insert a new column to the left of where the cursor is, then enter some text. I want the same text repeated down the entire column.

You can see what I have. If I get my desired text copied to the clipboard, then Selection.Paste does the job, but I'd prefer if the text came from the text box "txtColumn" that is on my user form.

Note that these two:
Code:
    Selection.TypeText (txtColumn.Value)
    Selection.InsertBefore Text:="teacher"
only insert the text into one cell (even if the entire column is selected).

Does this require a loop or something??
Ideas?


Code:
Private Sub cmdMakeColLeft_Click()
    Selection.InsertColumns
    Selection.MoveLeft Unit:=wdCell
    Selection.SelectColumn
    'Selection.TypeText (txtColumn.Value)
    'Selection.InsertBefore Text:="teacher"
    Selection.Paste
End Sub


Last edited by Steve Kunkel; 04-14-2021 at 07:23 PM. Reason: Added code tags; added solved
Reply With Quote
  #2  
Old 04-14-2021, 04:05 PM
Guessed's Avatar
Guessed Guessed is offline Want to Insert Column and add text into entire column. Windows 10 Want to Insert Column and add text into entire column. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Try this
Code:
Sub Macro2()
  Dim str As String, aCell As Cell
  Selection.InsertColumns  'or InsertColumnsRight
  str = InputBox("What do you want in each cell?", "Feed Me", "Hi mum")
  For Each aCell In Selection.Cells
    aCell.Range.Text = str
  Next aCell
End Sub
If you have a userform open and you want the text value to come from the field you could change the str line to
str = Me.txtColumn
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 04-14-2021, 07:22 PM
Steve Kunkel Steve Kunkel is offline Want to Insert Column and add text into entire column. Windows 10 Want to Insert Column and add text into entire column. Office 2019
Advanced Beginner
Want to Insert Column and add text into entire column.
 
Join Date: May 2019
Location: Seattle area
Posts: 77
Steve Kunkel is on a distinguished road
Default

Yes -- That works perfectly! Thanks Guessed!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Want to Insert Column and add text into entire column. Create formula for entire column tdodson Excel 2 10-27-2015 09:38 PM
Want to Insert Column and add text into entire column. Parsing 'FullName' column - help needed text to column ScottA Excel Programming 3 05-06-2014 12:49 PM
How to add a fixed value to an entire column? mikehende Excel 11 12-12-2012 02:47 PM
NETWORKDAYS calculation for entire column Salient Excel 0 07-11-2011 03:58 PM
Formula not getting copied to entire column theacegary Excel 1 11-29-2010 02:18 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:11 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