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:
___________________________________ -
Loop Macro that goes down list of clients changing the VLOOKUP on D34 on CONTROL tab
-
___________________________________
-
-
Sheets("CLIENT HOLDINGS").Select
-
Range("A2").Select
-
-
' Hide Rows with blanks for Addressing part of statement
-
On Error Resume Next
-
Do Until ActiveCell.Value = ""
-
If ActiveCell.Value <> "" Then
-
ActiveCell.Copy
-
Sheets("CONTROL").Select
-
Range("D34").Select
-
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
-
:=False, Transpose:=False
-
-
Sheets("Cache").Select
-
'Range("B23").Select
-
-
If Range("B23").Value <> "0" Then
-
-
Call TemplateCover
-
Windows("Distribution Statements(ORIGINAL).xls").Activate
-
-
Else:
-
-
End If
-
Sheets("CLIENT HOLDINGS").Select
-
ActiveCell.Offset(1, 0).Select
-
-
Else:
-
-
End If
-
Loop
-
-
-
___________________________________
-
TemplateCover macro (I8 = Client ID)
-
___________________________________
-
-
Sheets("TEMPLATE").Copy After:=Workbooks("Template Cover.xls").Sheets(1)
-
Cells.Select
-
Selection.Copy
-
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
-
:=False, Transpose:=False
-
-
Sheets("TEMPLATE").Name = Range("I8").Value
-
-
End Sub
4 2892
Your use of "On Error Resume Next" overrides any errors generated.
You should move the line... "ActiveCell.Offset(1, 0).Select"
downward to just before the word Loop.
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:
___________________________________ -
Loop Macro that goes down list of clients changing the VLOOKUP on D34 on CONTROL tab
-
___________________________________
-
-
Sheets("CLIENT HOLDINGS").Select
-
Range("A2").Select
-
-
' Hide Rows with blanks for Addressing part of statement
-
On Error Resume Next
-
Do Until ActiveCell.Value = ""
-
If ActiveCell.Value <> "" Then
-
ActiveCell.Copy
-
Sheets("CONTROL").Select
-
Range("D34").Select
-
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
-
:=False, Transpose:=False
-
-
Sheets("Cache").Select
-
'Range("B23").Select
-
-
If Range("B23").Value <> "0" Then
-
-
Call TemplateCover
-
Windows("Distribution Statements(ORIGINAL).xls").Activate
-
-
Else:
-
-
End If
-
Sheets("CLIENT HOLDINGS").Select
-
ActiveCell.Offset(1, 0).Select
-
-
Else:
-
-
End If
-
Loop
-
-
-
___________________________________
-
TemplateCover macro (I8 = Client ID)
-
___________________________________
-
-
Sheets("TEMPLATE").Copy After:=Workbooks("Template Cover.xls").Sheets(1)
-
Cells.Select
-
Selection.Copy
-
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
-
:=False, Transpose:=False
-
-
Sheets("TEMPLATE").Name = Range("I8").Value
-
-
End Sub
Thanks for your input but that does not solve the problem. By removing the "On error" line it produces the error message. I need the activecell.offset to move down the list of client ID references.
Excel seems to randomly decide when to be unable to copy/move the worksheet from one workbook another (template).
Still require help if anybody has an idea?
kadghar 1,295
Recognized Expert Top Contributor
Thanks for your input but that does not solve the problem. By removing the "On error" line it produces the error message. I need the activecell.offset to move down the list of client ID references.
Excel seems to randomly decide when to be unable to copy/move the worksheet from one workbook another (template).
Still require help if anybody has an idea?
Have in mind that you cannot copy-paste to a worksheet-workbook that is not visible, or active. Try activating the worksheet, workbook bevore pasting. Or instead of copy-paste, define a variable, save the value into the variable, and then write the variable into the other worksheet. This way, the sheets dont have to be (not even) visible.
I'll recomend you to delete a worksheet you've already printed, for you not to have an overflow.
Dököll 2,364
Recognized Expert Top Contributor
Hi,
...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:
___________________________________ -
Loop Macro that goes down list of clients changing the VLOOKUP on D34 on CONTROL tab
-
___________________________________
-
-
Sheets("CLIENT HOLDINGS").Select
-
Range("A2").Select
-
-
' Hide Rows with blanks for Addressing part of statement
-
On Error Resume Next
-
Do Until ActiveCell.Value = ""
-
If ActiveCell.Value <> "" Then
-
ActiveCell.Copy
-
Sheets("CONTROL").Select
-
Range("D34").Select
-
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
-
:=False, Transpose:=False
-
-
Sheets("Cache").Select
-
'Range("B23").Select
-
-
If Range("B23").Value <> "0" Then
-
-
Call TemplateCover
-
Windows("Distribution Statements(ORIGINAL).xls").Activate
-
-
Else:
-
-
End If
-
Sheets("CLIENT HOLDINGS").Select
-
ActiveCell.Offset(1, 0).Select
-
-
Else:
-
-
End If
-
Loop
-
-
-
___________________________________
-
TemplateCover macro (I8 = Client ID)
-
___________________________________
-
-
Sheets("TEMPLATE").Copy After:=Workbooks("Template Cover.xls").Sheets(1)
-
Cells.Select
-
Selection.Copy
-
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
-
:=False, Transpose:=False
-
-
Sheets("TEMPLATE").Name = Range("I8").Value
-
-
End Sub
Hey there MAdcock!
Thank you for submitting your code, and it's likely you have previously searched our forum and if you have not as of yet, please do or Google your title, see what pops up.
Also if you tell us whether a different way of achieving what you need would do just fine, let us know. Sorry for your troubles...
Dököll
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dayron |
last post by:
Hi,
I would like export the records retrieved from database to excel
worksheets. unfortunately, each worksheet will support until 65535
records and I have about 1 million of records to write. So I...
|
by: Joe Schmoe |
last post by:
I am working on an ASP.NET application that generates an Excel 2003
spreadsheet on demand for the user, containing much sales information, and
then editable cells for the salerep user to enter...
|
by: xhenxhe |
last post by:
I don't some Excel automation. I've created a program that opens and Excel
template and inputs information to it. It runs great on my machine. When I
build and deploy I have a user that keep...
|
by: madeleine.macphail |
last post by:
All
I'm currently attempting to move us from a spreadsheet based system to
a database system. The first phase is to import the data on a regular
basis from the spreadsheets to get the database...
|
by: dan_roman |
last post by:
Hi,
I developed a script with a nice interface in Tkinter that allows me to
edit some formulas and to generate an Excel worksheet with VBA macros
within it. The script runs perfectlly in Office...
| |
by: blainegray |
last post by:
Greetings
This is one of those Access is not closing Excel problems.
The first time through the code works fine. The second time there is a problem.
After lots of combinations, I finally...
|
by: NeoPa |
last post by:
Firstly, this is a very strange error and anyone throwing any light on this at all will be considered very clever indeed :D
OS = Win XP SP2
MS Excel 2000 SP3.
I get the error :
Path/File access...
|
by: anthony.gilliam |
last post by:
Hi readers,
Thanks for looking at this artical.
I've made an office project in C# based on an Excel Workbook
template. The project has checkbox controls on a worksheet
(worksheet1) that...
|
by: NeverLift |
last post by:
This is probably answered elsewhere, but I've searched the Web and VBA for Excel manual, find no answers.
I have a VBA-coded macro in an Excel workbook that is to open another existing workbook --...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |