I have this
It was working fine yesterday but today it is being difficult.
Here are my objectives.
1. Search column A for the text "avg"
2. Select Column E of that same row
3. Paste selected cell into myfile, bookmark "PRTable" Cell(3,4).
Here is what is happening when I run the code.
1. Copies the wrong cell
2. Pastes into every cell of the table.
Yesterday it was copying the correct cell, but was still pasting into the entire table.
Code:
Sub CopyAndPaste()
Dim myfile, wdApp As New Word.Application, wdDoc As Word.Document
myfile = Application.GetOpenFilename(, , "Browse for Document")
Dim lrow As Long, rng As Range, cell As Range
lrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set rng = Range("A2:A" & lrow)
For Each cell In rng
If InStr(1, cell.Value, "avg", vbTextCompare) > 0 Then
cell(0, 4).Select
Selection.Copy
End If
Next cell
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
Here are my objectives.
1. Search column A for the text "avg"
2. Select Column E of that same row
3. Paste selected cell into myfile, bookmark "PRTable" Cell(3,4).
Here is what is happening when I run the code.
1. Copies the wrong cell
2. Pastes into every cell of the table.
Yesterday it was copying the correct cell, but was still pasting into the entire table.