The following code copies data from Excel & pastes it as unformatted text into a new Word doc.
The range to be copied will always start at A15, but can consist of any number of rows & any number of columns up to & including H, e.g. A15:C300, A15:E20, A15:H2000, etc.
My problem is to find the last row & column with data.
The code below doesn't work properly -- the range selected includes cells with no visible data (false positives?), which create problems when copied into the Word doc.
Any help greatly appreciated! I'm a mere cutter & paster with little knowledge of VBA, so please feel free to underestimate my level of expertise.
______________________
Sub report()
Dim Rng As Range
Dim LastRow As Long
Range("A65536").Select
ActiveCell.End(xlUp).Select
LastRow = ActiveCell.Row
Set Rng = Range("A15" & ":" & "H" & LastRow)
Application.Goto Reference:=Rng
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
'open Word & paste
Dim appWD As Word.Application
Set appWD = CreateObject("Word.Application")
appWD.Visible = True
appWD.Documents.Add
appWD.Selection.PasteAndFormat (wdPasteDefault)
End Sub
The range to be copied will always start at A15, but can consist of any number of rows & any number of columns up to & including H, e.g. A15:C300, A15:E20, A15:H2000, etc.
My problem is to find the last row & column with data.
The code below doesn't work properly -- the range selected includes cells with no visible data (false positives?), which create problems when copied into the Word doc.
Any help greatly appreciated! I'm a mere cutter & paster with little knowledge of VBA, so please feel free to underestimate my level of expertise.
______________________
Sub report()
Dim Rng As Range
Dim LastRow As Long
Range("A65536").Select
ActiveCell.End(xlUp).Select
LastRow = ActiveCell.Row
Set Rng = Range("A15" & ":" & "H" & LastRow)
Application.Goto Reference:=Rng
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
'open Word & paste
Dim appWD As Word.Application
Set appWD = CreateObject("Word.Application")
appWD.Visible = True
appWD.Documents.Add
appWD.Selection.PasteAndFormat (wdPasteDefault)
End Sub