Unsure of code for Word cell range

klutch

New Member
Joined
Jun 7, 2018
Messages
38
Code:
    If Range("c2") = 22 Then wdoc.tables(7)Cell("B4").select
    If Range("c2") = 5 Then wdoc.tables(7)Cell("C4").select
    If Range("c2") = -20 Then wdoc.tables(7)Range("D4").select
This snippet of my code is clearly incorrect, but I believe you should be able to tell what I am trying to do. which is selecting a cell in a word table to paste into depending on variables.
The
Code:
 wdoc.tables(7)Cell("B4").select
is where I don't know what to do. I can select the table but the "Cell("B4")" portion is not the correct way to select that cell.
How do I write the code to do this?
This is picking off a previous thread in the Microsoft Office Forums
Here: http://www.msofficeforums.com/word-...s-multiple-documents-possible.html#post129784
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
This is what I have thus far
Code:
Sub CopyAndPaste()
    Dim myfile, wdApp As New Word.Application, wdDoc 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
 
    wdApp.Visible = True
    Set wdDoc = wdApp.Documents.Open(myfile)
    'selects the paste range in the performance review table, depending on the set point
    If Range("c2") = 22 Then wdoc.tables(7).Cell("B4").Select
    If Range("c2") = 5 Then wdoc.tables(7).Cell("C4").Select
    If Range("c2") = -20 Then wdoc.tables(7).Cell("D4").Select
    
    'and paste the clipboard contents
    wdApp.Selection.Collapse wdCollapseEnd
    wdApp.Selection.Paste
End Sub
This is giving me an object required error on this line: If Range("c2") = 5 Then wdoc.tables(7).Cell("C4").Select
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top