I have a macro that takes each row of data on a spreadsheet and creates a Word document. The problem I have is that all the rows have data in columns A:H but some may have data up to column Z. So when I transpose the range (H:Q) it caused my reports to have lots of blank fields or I am limiting my options. How can I transpose up to the last field on that row so that if there are only 2 records I will only use up to two rows on the report or if there are 50 records I will have 50 rows of data on the report? Below is a bit of the macro.
Sheets("Data").Select
'Find the last row with data in the database
FINALROW = Range("A9999").End(xlUp).Row
For i = 2 To FINALROW
Sheets("Data").Select
' Copy the name to cell
Range("A" & i).Copy Destination:=Sheets("Template").Range("b6")
Range("B" & i).Copy Destination:=Sheets("Template").Range("b7")
Range("C" & i).Copy Destination:=Sheets("Template").Range("b8")
Range("D" & i).Copy Destination:=Sheets("Template").Range("b10")
Range("E" & i).Copy Destination:=Sheets("Template").Range("b11")
Range("F" & i).Copy Destination:=Sheets("Template").Range("b12")
Range("G" & i).Copy Destination:=Sheets("Template").Range("b5")
Range("H" & i & ":Q" & i).Copy
Sheets("Template").Select
Range("b20").PasteSpecial Transpose:=True
' Copy the data for the new document to the clipboard
Please advise. Thanks in advance!
Sheets("Data").Select
'Find the last row with data in the database
FINALROW = Range("A9999").End(xlUp).Row
For i = 2 To FINALROW
Sheets("Data").Select
' Copy the name to cell
Range("A" & i).Copy Destination:=Sheets("Template").Range("b6")
Range("B" & i).Copy Destination:=Sheets("Template").Range("b7")
Range("C" & i).Copy Destination:=Sheets("Template").Range("b8")
Range("D" & i).Copy Destination:=Sheets("Template").Range("b10")
Range("E" & i).Copy Destination:=Sheets("Template").Range("b11")
Range("F" & i).Copy Destination:=Sheets("Template").Range("b12")
Range("G" & i).Copy Destination:=Sheets("Template").Range("b5")
Range("H" & i & ":Q" & i).Copy
Sheets("Template").Select
Range("b20").PasteSpecial Transpose:=True
' Copy the data for the new document to the clipboard
Please advise. Thanks in advance!