473,491 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Copying Worksheet to another Workbook - ERROR

13 New Member
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:

___________________________________

Expand|Select|Wrap|Line Numbers
  1. Loop Macro that goes down list of clients changing the VLOOKUP on D34 on CONTROL tab
  2. ___________________________________
  3.  
  4. Sheets("CLIENT HOLDINGS").Select
  5. Range("A2").Select
  6.  
  7. ' Hide Rows with blanks for Addressing part of statement
  8. On Error Resume Next
  9. Do Until ActiveCell.Value = ""
  10. If ActiveCell.Value <> "" Then
  11.     ActiveCell.Copy
  12.     Sheets("CONTROL").Select
  13.     Range("D34").Select
  14.     Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
  15.         :=False, Transpose:=False
  16.  
  17.     Sheets("Cache").Select
  18.     'Range("B23").Select
  19.  
  20.         If Range("B23").Value <> "0" Then
  21.  
  22.             Call TemplateCover
  23.             Windows("Distribution Statements(ORIGINAL).xls").Activate
  24.  
  25.         Else:
  26.  
  27.         End If
  28.     Sheets("CLIENT HOLDINGS").Select
  29.     ActiveCell.Offset(1, 0).Select
  30.  
  31. Else:
  32.  
  33. End If
  34. Loop
  35.  
  36.  
  37. ___________________________________
  38. TemplateCover macro (I8 = Client ID)
  39. ___________________________________
  40.  
  41. Sheets("TEMPLATE").Copy After:=Workbooks("Template Cover.xls").Sheets(1)
  42.     Cells.Select
  43.     Selection.Copy
  44.     Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
  45.         :=False, Transpose:=False
  46.  
  47.     Sheets("TEMPLATE").Name = Range("I8").Value
  48.  
  49. End Sub
Apr 30 '08 #1
4 2892
ubentook
58 New Member
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:

___________________________________

Expand|Select|Wrap|Line Numbers
  1. Loop Macro that goes down list of clients changing the VLOOKUP on D34 on CONTROL tab
  2. ___________________________________
  3.  
  4. Sheets("CLIENT HOLDINGS").Select
  5. Range("A2").Select
  6.  
  7. ' Hide Rows with blanks for Addressing part of statement
  8. On Error Resume Next
  9. Do Until ActiveCell.Value = ""
  10. If ActiveCell.Value <> "" Then
  11.     ActiveCell.Copy
  12.     Sheets("CONTROL").Select
  13.     Range("D34").Select
  14.     Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
  15.         :=False, Transpose:=False
  16.  
  17.     Sheets("Cache").Select
  18.     'Range("B23").Select
  19.  
  20.         If Range("B23").Value <> "0" Then
  21.  
  22.             Call TemplateCover
  23.             Windows("Distribution Statements(ORIGINAL).xls").Activate
  24.  
  25.         Else:
  26.  
  27.         End If
  28.     Sheets("CLIENT HOLDINGS").Select
  29.     ActiveCell.Offset(1, 0).Select
  30.  
  31. Else:
  32.  
  33. End If
  34. Loop
  35.  
  36.  
  37. ___________________________________
  38. TemplateCover macro (I8 = Client ID)
  39. ___________________________________
  40.  
  41. Sheets("TEMPLATE").Copy After:=Workbooks("Template Cover.xls").Sheets(1)
  42.     Cells.Select
  43.     Selection.Copy
  44.     Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
  45.         :=False, Transpose:=False
  46.  
  47.     Sheets("TEMPLATE").Name = Range("I8").Value
  48.  
  49. End Sub
May 1 '08 #2
MAdcock
13 New Member
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?
May 1 '08 #3
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.
May 2 '08 #4
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:

___________________________________

Expand|Select|Wrap|Line Numbers
  1. Loop Macro that goes down list of clients changing the VLOOKUP on D34 on CONTROL tab
  2. ___________________________________
  3.  
  4. Sheets("CLIENT HOLDINGS").Select
  5. Range("A2").Select
  6.  
  7. ' Hide Rows with blanks for Addressing part of statement
  8. On Error Resume Next
  9. Do Until ActiveCell.Value = ""
  10. If ActiveCell.Value <> "" Then
  11.     ActiveCell.Copy
  12.     Sheets("CONTROL").Select
  13.     Range("D34").Select
  14.     Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
  15.         :=False, Transpose:=False
  16.  
  17.     Sheets("Cache").Select
  18.     'Range("B23").Select
  19.  
  20.         If Range("B23").Value <> "0" Then
  21.  
  22.             Call TemplateCover
  23.             Windows("Distribution Statements(ORIGINAL).xls").Activate
  24.  
  25.         Else:
  26.  
  27.         End If
  28.     Sheets("CLIENT HOLDINGS").Select
  29.     ActiveCell.Offset(1, 0).Select
  30.  
  31. Else:
  32.  
  33. End If
  34. Loop
  35.  
  36.  
  37. ___________________________________
  38. TemplateCover macro (I8 = Client ID)
  39. ___________________________________
  40.  
  41. Sheets("TEMPLATE").Copy After:=Workbooks("Template Cover.xls").Sheets(1)
  42.     Cells.Select
  43.     Selection.Copy
  44.     Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
  45.         :=False, Transpose:=False
  46.  
  47.     Sheets("TEMPLATE").Name = Range("I8").Value
  48.  
  49. 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
May 3 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3253
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...
0
1310
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...
2
15307
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...
1
2779
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...
3
3981
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...
0
3019
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...
3
4703
NeoPa
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...
1
1770
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...
7
93643
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 --...
0
7115
marktang
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,...
0
6978
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...
0
7190
jinu1996
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...
0
7360
tracyyun
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...
0
5451
agi2029
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,...
1
4881
isladogs
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...
0
4578
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...
0
1392
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 ...
0
280
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.