PDA

View Full Version : COPY CERTAIN COLUMN IF ROW CONTAINS CERTAIN DATA FROM EXCEL TO WORD



Gautam489
11-23-2020, 12:38 AM
Help Please,

Hello there. i am trying to copy columns a,k,l and m column, if there is data in column m, with following code, however i cant do as t copy whole column from a to m.

Code is

Sub ExcelWord()


Dim wdApp As Object
Dim wd As Object
Dim c As Range


On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
Set Source = ActiveWorkbook.Worksheets("Sheet1")
If Err.Number <> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0


Set wd = wdApp.Documents.Add


wdApp.Visible = True
For Each c In Source.Range("m4:m1000") ' Do 1000 rows
If c > 1 Then
Source.Range(Cells(c.Row, 1), Cells(c.Row, 14)).Copy
wdApp.Selection.PasteExcelTable False, False, False
End If


Next c
End Sub

snb
11-23-2020, 04:51 AM
You'd better start in Excel VBA Programming For Dummies by John Walkenbach | 9781119077398 | Paperback | Barnes & Noble (http://www.barnesandnoble.com/w/excel-vba-programming-for-dummies-john-walkenbach/1101874584) first.