Used same VBA code in another Workbook with updated worksheet and cell addresses but macro hangs in new Workbook

Cyowa

New Member
Joined
Apr 12, 2008
Messages
4
Hello,

I have this macro in a worksheet that runs as expected:

Sub COPY_CASES_TO_ROWS()
' COPY_CASES_TO_ROWS Macro
'
Dim X As Long
For X = 1 To Range("AE2")
'For X = 1 To 1 Step 1

Sheets("Case_COL").Select
'Calculate
Range("D3:ALO3").Select
Selection.Copy
Range("D2").End(xlDown).Offset(1, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("D2").End(xlDown).Offset(1, 0).Range("A1").Select
Application.CutCopyMode = False
Next X

End Sub


...so I created a new macro name in another workbook and copied the above macro to that workbook and modified the worksheet and cell names & locations for the new workbook:

Sub BSM_COPY_ITERATIONS_01()
'
' BSM_COPY_ITERATIONS_01 Macro
' Copy BSM iterations to charting range
'
Sheets("BSM").Select
Dim X As Long
For X = 1 To Range("B508")
'For X = 1 To 1 Step 1

Sheets("BSM").Select
Range("C2:U2").Select
Selection.Copy
Range("C510").End(xlDown).Offset(1, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("C510").End(xlDown).Offset(1, 0).Range("A1").Select
Application.CutCopyMode = False
Next X

End Sub

...but the new workbook macro hangs at the above highlighted line when I run the debugger...

I've tried to determine what I've got wrong with the new macro but haven't been able to figure it out.

Any help is appreciated, thank you.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

mart37

Well-known Member
Joined
Aug 4, 2017
Messages
1,091
Office Version
  1. 2016
Platform
  1. Windows
Are the cells below C510 filled?
 

mohadin

Well-known Member
Joined
Mar 22, 2015
Messages
1,091
Office Version
  1. 2013
Platform
  1. Windows
Hi
Try
If you need to select Range("C511") down
Should loo like:
VBA Code:
Range("C510").End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Next X

Or
VBA Code:
Range("C510").End(xlDown).Offset(1, 0).PasteSpecial Paste:=xlPasteValues,
Application.CutCopyMode = False
Next X
 

Cyowa

New Member
Joined
Apr 12, 2008
Messages
4
Thank you for the responses.

Mart37 - Your question made me think and go back and take another look at my cell addresses in the new macro...the mistake I made was that I needed to move my starting cell address back up to C509 (both C509 and C510 have values in them) so that the macro selected the first open cell (C511) below the last cell with a value in it (C510) and the data being copied would then be amended to the range at the first open cell...then iterate to the next X value (C509 > C511) > (C509 > C512) > (C509 > C513) > (C509 > C514) and so on until the last iteration of X was completed.

Thank you both for your responses and help...
 

Watch MrExcel Video

Forum statistics

Threads
1,129,590
Messages
5,637,285
Members
416,963
Latest member
samfuge

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
Top