View Single Post
 
Old 03-18-2022, 05:58 PM
gbrew584 gbrew584 is offline Windows 7 64bit Office 2013
Novice
 
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