Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | Keep on getting a Windows Error Sound - Help

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > General IT Discussion

Macro question in Excel
Reply
 
Thread Tools
Old 16-01-2007, 02:12   #1
absthechatter
Inactive
 
Join Date: Dec 2004
Posts: 310
absthechatter is just really niceabsthechatter is just really niceabsthechatter is just really niceabsthechatter is just really niceabsthechatter is just really niceabsthechatter is just really nice
Macro question in Excel

I have a Macro, to copy two columns and paste in, further to the left;

Next lngLoop
Sheets("CCReport").Activate
Columns("E:F").Select
Application.CutCopyMode = False
Selection.Cut
Columns("B:B").Select
Selection.Insert Shift:=xlToRight
Range("B2").Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft

Range("B1").Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft

This works absoloutely fine on my home computer (Office 2003), but whenever I try it at work (Office 2000), I get the information cannot be pasted because the cut area and paste area are not the same size (Run-time error '1004'.

Is this just a problem with earlier versions of Excel, or is there a way i can fix it so it runs on my work computer.

Many thanks

Abs
absthechatter is offline   Reply With Quote
Advertisement
Old 16-01-2007, 10:33   #2
gazzae
Inactive
 
gazzae's Avatar
 
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
Re: Macro question in Excel

Why have you a NEXT at the top? That probably causing the error as there is no FOR. Assuming that is your whole code of course.
gazzae is offline   Reply With Quote
Old 16-01-2007, 11:08   #3
PC_Arcade
Inactive
 
Join Date: Jul 2003
Posts: 259
PC_Arcade has a spectacular aura about themPC_Arcade has a spectacular aura about themPC_Arcade has a spectacular aura about themPC_Arcade has a spectacular aura about them
Re: Macro question in Excel

Quote:
Originally Posted by absthechatter View Post
Next lngLoop
Sheets("CCReport").Activate
Columns("E:F").Select
Application.CutCopyMode = False
Selection.Cut
Range("B1").Select
Selection.Insert Shift:=xlToRight

Range("b2").Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft

Range("B1").Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft

This works absoloutely fine on my home computer (Office 2003), but whenever I try it at work (Office 2000), I get the information cannot be pasted because the cut area and paste area are not the same size (Run-time error '1004'.

Is this just a problem with earlier versions of Excel, or is there a way i can fix it so it runs on my work computer.

Many thanks

Abs
I've changed the bold lines above, does that work?
It's to do with the fact that according to excel 2000 you're trying to past two columns (E&F) into one (B) if you select the cell rather than the column before you paste it should insert correctly

I use macros all the time, but it's been a while since I've used excel2000
PC_Arcade is offline   Reply With Quote
Old 16-01-2007, 11:32   #4
gazzae
Inactive
 
gazzae's Avatar
 
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
Re: Macro question in Excel

The code works fine in Excel 2000 once the next line is removed.

---------- Post added at 10:32 ---------- Previous post was at 10:20 ----------

Macros aren't very efficent.

This performs the same function in half the lines

With Worksheets("ccreport")
.Range("E:F").Cut
.Range("B:C").Insert
.Range("b1:c2").ClearContents
End With
Application.CutCopyMode = False
gazzae is offline   Reply With Quote
Old 16-01-2007, 12:15   #5
absthechatter
Inactive
 
Join Date: Dec 2004
Posts: 310
absthechatter is just really niceabsthechatter is just really niceabsthechatter is just really niceabsthechatter is just really niceabsthechatter is just really niceabsthechatter is just really nice
Re: Macro question in Excel

Quote:
Originally Posted by gazzae View Post
Why have you a NEXT at the top? That probably causing the error as there is no FOR. Assuming that is your whole code of course.
Thanks Gazzae, it is not the whole code, only a small part of it. Everything works fine up to this point, and then it has problems with the pasting. Have tried the two methods and still not working on Excel 2000, although fine on 2003.

Abs

---------- Post added at 11:15 ---------- Previous post was at 11:09 ----------

Actually starting to get somewhere now, with your shortened code gazzae!! It is now cutting columns E & F and attempting to paste, but I get cannot change part of a merged cell. Any ideas?

Abs
absthechatter is offline   Reply With Quote
Old 16-01-2007, 13:05   #6
gazzae
Inactive
 
gazzae's Avatar
 
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
Re: Macro question in Excel

In my code if I make a merged cell from D1 to F1 then it causes the same error as you.
gazzae is offline   Reply With Quote
Old 16-01-2007, 13:36   #7
absthechatter
Inactive
 
Join Date: Dec 2004
Posts: 310
absthechatter is just really niceabsthechatter is just really niceabsthechatter is just really niceabsthechatter is just really niceabsthechatter is just really niceabsthechatter is just really nice
Re: Macro question in Excel

Got away with....

Next lngLoop
Sheets("CCReport").Activate
Columns("E:F").Select
Application.CutCopyMode = False
Selection.Cut
Range("B1").Insert
Range("B2").Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft

Range("B1").Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft



It appears to work. Probably more than I need to write... but!!

Many thanks for all your help.

Abs
absthechatter is offline   Reply With Quote
Old 16-01-2007, 13:48   #8
gazzae
Inactive
 
gazzae's Avatar
 
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
Re: Macro question in Excel

Most have been your merged cells that were causing the error.

As for the last 6 lines of your code you can simply use..

Range("b1:c2").Delete
gazzae is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 17:10.


Server: osmium.zmnt.uk
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum