Hi,
I have created an excel program which creates 65 or more (nneds to be unlimited) customised letters for clients. The macro uses VLOOKUP to change the details within the letter and copies / moves the work sheet to another "template file" which contains printing macros etc. Each new worksheet is subsequently renamed to the Client ID reference.
The program is meant to do all applicable clients letters and then saves the template accordingly. Unfortunately for some reason the macro will run perfectly one time and then the next will not copy once it reaches a random client, or do I mean just doesn't do the copy.
The macro does not stop and provide the dreaded excel error message at all. The macro simply carries on the loop, changing the letters details etc but not copying the worksheet to the template file. Once the maco has finished, even if I try a manual move/copy it simply does not do it! is this just one of those extremely annyoing things with Excel? If i close excel and start up again and run the same macro, the macro will either complete as required or do exactly the same again. When I initially created the macro all worked fine!
Is there a way of forcing the copy to happen or checking that each worksheet has been created in the template file?
Your help is much appreciated.
My code is below:
_______________ _______________ _____
[CODE=VB]
Loop Macro that goes down list of clients changing the VLOOKUP on D34 on CONTROL tab
_______________ _______________ _____
Sheets("CLIENT HOLDINGS").Sele ct
Range("A2").Sel ect
' Hide Rows with blanks for Addressing part of statement
On Error Resume Next
Do Until ActiveCell.Valu e = ""
If ActiveCell.Valu e <> "" Then
ActiveCell.Copy
Sheets("CONTROL ").Select
Range("D34").Se lect
Selection.Paste Special Paste:=xlPasteV alues, Operation:=xlNo ne, SkipBlanks _
:=False, Transpose:=Fals e
Sheets("Cache") .Select
'Range("B23").S elect
If Range("B23").Va lue <> "0" Then
Call TemplateCover
Windows("Distri bution Statements(ORIG INAL).xls").Act ivate
Else:
End If
Sheets("CLIENT HOLDINGS").Sele ct
ActiveCell.Offs et(1, 0).Select
Else:
End If
Loop
_______________ _______________ _____
TemplateCover macro (I8 = Client ID)
_______________ _______________ _____
Sheets("TEMPLAT E").Copy After:=Workbook s("Template Cover.xls").She ets(1)
Cells.Select
Selection.Copy
Selection.Paste Special Paste:=xlPasteV alues, Operation:=xlNo ne, SkipBlanks _
:=False, Transpose:=Fals e
Sheets("TEMPLAT E").Name = Range("I8").Val ue
End Sub[/CODE]
I have created an excel program which creates 65 or more (nneds to be unlimited) customised letters for clients. The macro uses VLOOKUP to change the details within the letter and copies / moves the work sheet to another "template file" which contains printing macros etc. Each new worksheet is subsequently renamed to the Client ID reference.
The program is meant to do all applicable clients letters and then saves the template accordingly. Unfortunately for some reason the macro will run perfectly one time and then the next will not copy once it reaches a random client, or do I mean just doesn't do the copy.
The macro does not stop and provide the dreaded excel error message at all. The macro simply carries on the loop, changing the letters details etc but not copying the worksheet to the template file. Once the maco has finished, even if I try a manual move/copy it simply does not do it! is this just one of those extremely annyoing things with Excel? If i close excel and start up again and run the same macro, the macro will either complete as required or do exactly the same again. When I initially created the macro all worked fine!
Is there a way of forcing the copy to happen or checking that each worksheet has been created in the template file?
Your help is much appreciated.
My code is below:
_______________ _______________ _____
[CODE=VB]
Loop Macro that goes down list of clients changing the VLOOKUP on D34 on CONTROL tab
_______________ _______________ _____
Sheets("CLIENT HOLDINGS").Sele ct
Range("A2").Sel ect
' Hide Rows with blanks for Addressing part of statement
On Error Resume Next
Do Until ActiveCell.Valu e = ""
If ActiveCell.Valu e <> "" Then
ActiveCell.Copy
Sheets("CONTROL ").Select
Range("D34").Se lect
Selection.Paste Special Paste:=xlPasteV alues, Operation:=xlNo ne, SkipBlanks _
:=False, Transpose:=Fals e
Sheets("Cache") .Select
'Range("B23").S elect
If Range("B23").Va lue <> "0" Then
Call TemplateCover
Windows("Distri bution Statements(ORIG INAL).xls").Act ivate
Else:
End If
Sheets("CLIENT HOLDINGS").Sele ct
ActiveCell.Offs et(1, 0).Select
Else:
End If
Loop
_______________ _______________ _____
TemplateCover macro (I8 = Client ID)
_______________ _______________ _____
Sheets("TEMPLAT E").Copy After:=Workbook s("Template Cover.xls").She ets(1)
Cells.Select
Selection.Copy
Selection.Paste Special Paste:=xlPasteV alues, Operation:=xlNo ne, SkipBlanks _
:=False, Transpose:=Fals e
Sheets("TEMPLAT E").Name = Range("I8").Val ue
End Sub[/CODE]
Comment