View Single Post
 
Old 07-05-2018, 07:13 AM
klutch klutch is offline Windows 7 64bit Office 2016
Advanced Beginner
 
Join Date: Jun 2018
Posts: 31
klutch is on a distinguished road
Default

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)
   
    'makes the file appear
    wdApp.Visible = True
    Set wDoc = wdApp.Documents.Open(myfile)
    
    With wDoc


Dim my_cell                                         As Word.Cell
Dim my_index                                        As Long

    For my_index = 1 To this_range.Cells.Count
        With this_range
            If Len(.Cells(my_index).Range.Text) <= 2 Then
                find_last_empty_cell_in_range = my_index
                Exit Sub
            End If
        End With
    Next
End With
Dim my_range                            As Word.Range

    Set my_range = ActiveDocument.Tables(8).Range

    Debug.Print find_last_empty_cell_in_range(my_range)
 
End Sub
This is how I added that into my code and got an error on the line
Code:
 For my_index = 1 To this_range.Cells.Count
I have found a way to select the column that I want to go to with
Code:
wDoc.Tables(8).Columns(3).Select
but how do I select the first empty cell?
I found this online
Code:
Dim x As Long
Dim crange As Range
With Selection
    For x = 1 To .Cells.Count
        Set crange = .Cells(x).Range
        With crange
            
            If Len(.Text) <> 0 Then
                .Select
                Exit For
            End If
        End With
    Next x
End With
Selection.Cells(1).Select

Selection.TypeText Text:=Range("e" & i)
but it gives me error as well and only selects the entire column opposed to the first empty cell
Reply With Quote