View Single Post
  #21   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default How to copy rows into an Excel *template* with vba

I would run a few more times and see if Q is the problem. Maybe eliminate Q
and see if it consistantly runs. The problem seems releated to the data in
the range of cells and not VBA code. Can you post the formula that is in
cell Q that is causing the problem?

I have three thoughts about this problem
1) There is some sort of circular equation that is causing the problem.
2) There is a reference to another workbook that is causing the problem.
Error 400 is sometimes cause by network files being available.
3) The templet workbook is corrupted. Sometimes copying the worksheet to a
new workbook solves the problem. Copying the workbook usually doesn't
correct these probelms because the error is also copied. You have to copy
the individual worksheets.

I had a workbook that when I opened said there was links that needed to be
updated. Try to find the link and couldn't. Deleted each worksheet except
for one sheet and still had the problem. Search the worksheet and couldn't
find the link. Deleted everything on the worksheet and still was getting the
error when the wrokbook was opened. The error was buried inside the excel
file and couldn't be removed. Copied the worksheets to a new workbook and
didn't get the error.

"Mikaela" wrote:

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.