View Single Post
  #20   Report Post  
Posted to microsoft.public.excel.programming
Mikaela Mikaela is offline
external usenet poster
 
Posts: 15
Default How to copy rows into an Excel *template* with vba

Have run this and these are the results:

1st try - the msgbox pops up stating "Error in cell ". (strangely there was
no cell address appended to the msg).
2nd try - received this error "Run-time error '1004'. Application-defined or
object-defined error". The autofill ceases to run at column Q.

3rd try and onwards the code ran smoothly without any problem. The
inconsistency of the results is very peculiar as I didn't modify the code in
between any of the tries.....

"Joel" wrote:

If you are still getting an error try this code to help isolate the problem.
It may be related to data on the templet. This code loops through the
columms A23:BT23 and tries to find which column data is causing the error

Sub test()

'
Set fs = CreateObject("Scripting.FileSystemObject")
'
With ThisWorkbook.Sheets("MasterList")
Workbooks.Add _
Template:="C:\MasterList\template.xlt"
Set NewBook = ActiveWorkbook
Set NewTempl = NewBook.Sheets("Template")
Set NewTempl1 = NewBook.Sheets("Template1")
NewTempl.Select

On Error GoTo err1
Prod_Count = 5
NewTempl.Unprotect ("12345678")
NewTempl.Activate
For Colcount = 1 To Range("BT23").Column
lastcelladdr = Cells(23, Colcount).Address
FromRange = "A23:" & lastcelladdr
lastcelladdr = Cells(27, Colcount).Address
ToRange = "A23:" & lastcelladdr
NewTempl.Range(FromRange).Select
Selection.AutoFill _
Destination:= _
NewTempl.Range(ToRange), _
Type:=xlFillDefault
Next Colcount
End With
Exit Sub
err1: MsgBox ("Error in cell " & lastcelladdr)
End Sub


"Mikaela" wrote:

First time thru the loop.