When I add the following code, a previously well running macro freezes

theblacknight

New Member
Joined
Apr 16, 2012
Messages
4
Code:
Set crange = Worksheets(3).Range(Worksheets(3).Cells(5, 2), Worksheets(3).Cells(2, 5).End(xlDown))
    Set prange = Worksheets(4).Cells(1, 26)
    
    crange.Copy
    prange.PasteSpecial Paste:=xlPasteValues
 
    Set crange = Worksheets(3).Range(Worksheets(3).Cells(203, 2), Worksheets(3).Cells(203, 2).End(xlDown))
    Set prange = Worksheets(4).Range(1, 26).End(xlDown).Offset(1, 0)
    crange.Copy
    prange.PasteSpecial Paste:=xlPasteValues
    Set crange = Nothing
    Set prange = Nothing
(sorry for the poor formatting- but I'm posting from my office and I can't download any addins etc)

Any idea why the above code would cause a macro to copy paste different columns? All I want to do is select two ranges and paste them into another sheet. The wierd thing is when I press escape, the line where the break occurs is not in this section of the code. btw I'm a total newbie at programming so sorry if this is a stupid question.
 
Last edited by a moderator:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Do you by any chance have Worksheet_Change event code that is being triggered by this macro?
 
Upvote 0
I don't think so; none of my work involves Worksheet_Change event code.

Although I do have bloomberg terminal addins for functions (live data feeds) , I am currently executing the code from a computer without a terminal.


btw I am searching for a way to copy paste two ranges which can change in size (number of rows changes) to another sheet. Have there been previous questions asked about this topic (am currently searching the forums).
 
Upvote 0
I would imagine so - it's a fairly common question.

What is the code that shows up when you debug then?
 
Upvote 0
I'm sorry Rorya, it appears i was executing bad code elsewhere (which seems to be fixed now).


with the following code what seems to be happening is that the macro is caught in an infinite loop. I could paste the whole macro, but since its technically company property I'm not sure whether that's wise (even though the code itself is kinda amateurish). I commented the section out for now (been experimenting with it for a while.

' Set crange = Worksheets(3).Range(Worksheets(3).Cells(5, 2), Worksheets(3).Cells(2, 5).End(xlDown))
' Set prange = Worksheets(4).Cells(1, 26)

' crange.Copy
' prange.PasteSpecial Paste:=xlPasteValues
' Application.CutCopyMode = False

' Set crange = Worksheets(3).Range(Worksheets(3).Cells(203, 2), Worksheets(3).Cells(203, 2).End(xlDown))
' Set prange = Worksheets(4).Range(1, 26).End(xlDown).Offset(1, 0)
' crange.Copy
' prange.PasteSpecial Paste:=xlPasteValues
' Set crange = Nothing
' Set prange = Nothing
' Application.CutCopyMode = False
 
Upvote 0
I can't see how that could get caught in an infinite loop unless it is being called by event code of some sort.
 
Upvote 0
Yeah, may have to look and see what's going on. As I said, I'm a total clueless newbie. In anycase I'll try and keep you updated if I find a solution.
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top