Two things: Creating a Pass Fail loop, Identifying cells with text in them

klutch

New Member
Joined
Jun 7, 2018
Messages
38
Hello, I have written code to copy and paste selected data from excel to a word table. In this I have accomplished A.) identifying the cell I need to copy B.) pasting that cell in a specific row in a word table. C.) type text "Performance Review" in column A of the new data row. D.) changing the font to match the word doc, as well as changing the color of that row of the table.
Here it is:
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
Now what I am seeking to do is:
1. Write another few lines of code to determine if the data pass or fails our standards (if x is between # and # then pass. If x is outside of # and # then fail) and then type text PASS/FAIL into another cell of the word table. I have failed at this thus far, I have been trying to use IF statements.
2. Is it possible for VBA to identify if a word table cell is already populated with text? and if so, is there a way so that the macro will paste the new data in the cell below?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,215,593
Messages
6,125,715
Members
449,254
Latest member
Eva146

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