Code:
Sub CopyAndPaste()
Dim myfile, wdApp As New Word.Application, wDoc As Word.Document
'select truck report file
ChDrive "E:\"
ChDir "E:\WG\TVAL\"
myfile = Application.GetOpenFilename(, , "Browse for Document")
Dim i As Integer
'searches for row with "avg" then selects column E(avg of temperature mean) of that row.
i = Application.Match("Avg", Sheet1.Range("A1:A20"), 0)
'copies the cell
Range("E" & i).Select
Selection.Copy
'makes the file appear
wdApp.Visible = True
Set wDoc = wdApp.Documents.Open(myfile)
With wDoc
'selects the paste range in the performance review table, depending on the set point
If Range("c2") = 22 Then wDoc.Tables(8).Cell(4, 1).Select
If Range("c2") = 5 Then wDoc.Tables(8).Cell(4, 2).Select
If Range("c2") = -20 Then wDoc.Tables(8).Cell(4, 3).Select
'and paste the clipboard contents
wdApp.Selection.Collapse wdCollapseEnd
wdApp.Selection.Paste
wdApp.Selection.Font.Name = "Times New Roman"
wdApp.Selection.Font.Size = 12
wdApp.Selection.Font.Bold = wdToggle
Application.CutCopyMode = False
Application.ScreenUpdating = True
wDoc.Tables(8).Cell(4, 0).Select
wdApp.Selection.TypeText Text:="Performance Review"
wDoc.Tables(8).Rows(4).Select
wdApp.Selection.Shading.Texture = wdTextureNone
wdApp.Selection.Shading.ForegroundPatternColor = wdColorAutomatic
wdApp.Selection.Shading.BackgroundPatternColor = -603914241
End With
wDoc.Save
End Sub
This is what I have right now. It works, but the problem is that if I wish to run it again it just pastes over the previous data. Which is why I need to search for the first blank cell, or have the user select where the macro will paste.