Cable Forum

Cable Forum (https://www.cableforum.uk/board/index.php)
-   General IT Discussion (https://www.cableforum.uk/board/forumdisplay.php?f=19)
-   -   Macro question in Excel (https://www.cableforum.uk/board/showthread.php?t=33606362)

absthechatter 16-01-2007 02:12

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.:confused:

Many thanks

Abs

gazzae 16-01-2007 10:33

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.

PC_Arcade 16-01-2007 11:08

Re: Macro question in Excel
 
Quote:

Originally Posted by absthechatter (Post 34198478)
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.:confused:

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

gazzae 16-01-2007 11:32

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

absthechatter 16-01-2007 12:15

Re: Macro question in Excel
 
Quote:

Originally Posted by gazzae (Post 34198520)
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

gazzae 16-01-2007 13:05

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.

absthechatter 16-01-2007 13:36

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

gazzae 16-01-2007 13:48

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


All times are GMT +1. The time now is 14:48.

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