Hello, I have been looking for a way to code my workbook to copy a cell from excel and paste it into a bookmarked table I have in word. I was hoping to be able to paste it into specific cells depending on data from my worksheet. Here is what I have so for
How can I change this to paste the data into cell(3,4) of the table?
In addition to this, would I be able to paste in different cells depending on the data?
Ex. If range("c2") = 22 then paste in bookmark cell(2,4)
If range("C2")= 5 then paste in bookmark cell(3,4)
If range("C2")= -20 then paste in bookmark cell(4,4)
Code:
Sub CopyAndPaste()
'opens libraries to select desired file
Dim myfile, wdApp As New Word.Application, wdDoc As Word.Document
myfile = Application.GetOpenFilename(, , "Browse for Document")
Dim i As Integer
i = Application.Match("Avg", Sheet1.Range("A1:A20"), 0)
Range("E" & i).Select
Selection.Copy
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open(myfile)
'select the word range you want to paste into
wdDoc.Bookmarks("PRtable").Select
'and paste the clipboard contents
wdApp.Selection.Paste
End Sub
In addition to this, would I be able to paste in different cells depending on the data?
Ex. If range("c2") = 22 then paste in bookmark cell(2,4)
If range("C2")= 5 then paste in bookmark cell(3,4)
If range("C2")= -20 then paste in bookmark cell(4,4)