Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-18-2022, 05:58 PM
gbrew584 gbrew584 is offline Trying to get the shortest line of code for copying from one cell to the next Windows 7 64bit Trying to get the shortest line of code for copying from one cell to the next Office 2013
Novice
Trying to get the shortest line of code for copying from one cell to the next
 
Join Date: Apr 2015
Location: Ohio
Posts: 28
gbrew584 is on a distinguished road
Default Trying to get the shortest line of code for copying from one cell to the next

Hi, all and thanks for reading my question. I am not very good with vba but I am trying to learn. while I was practicing, I was wondering how short I could make a line of code.





So I made a word document that consist of 1 table. The table is 5 columns with 2 rows. In the fist cell on the first row I have the text "is this working".


I am trying to copy the text from the first cell on row 1 to the first cell on row 2.


I ran the code below. It captures the desired text but it doesn't leave (or insert, input) the text in the cell on row 2. (sorry if I am not using the correct terminology)



I think maybe the T1 and T2 variables are wrong but I am not sure what they should be other than String.


If someone could please let me know what I am missing I would appreciate it.



Sub CopyPaste1() ' copy information from 1 cell


Dim AD As Document
Dim TB As Tables
Dim ST As Integer
Dim C1 As Cell
Dim C2 As Cell
Dim RG1 As Range
Dim RG2 As Range
Dim T1 As String
Dim T2 As String

Set AD = ActiveDocument
Set TB = AD.Tables
ST = 1
Set C1 = TB(ST).Cell(1, 1)
Set C2 = TB(ST).Cell(2, 1)
Set RG1 = C1.Range
Set RG2 = C2.Range
T1 = RG1.Text
T2 = RG2.Text

T2 = Left(T1, Len(T1) - TB(ST).Rows.Count)

End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying cell data from one tab to another tab tlmy87 Excel 0 12-23-2016 07:54 AM
Arrange shortest to longest sentence in Word omar Word 8 11-20-2015 04:38 PM
Trying to get the shortest line of code for copying from one cell to the next Copying a Changing cell value to one cell mbesspiata Excel 1 04-29-2014 02:16 PM
Copying data from one cell to another where condition is third cell fairyca Excel 4 03-30-2014 08:22 AM
Copying part of a cell to a new cell paulw793 Excel 7 01-27-2012 10:46 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:15 PM.


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