VBA code jumping back to start of sub

K1600

Board Regular
Joined
Oct 20, 2017
Messages
181
I have the below code which simply copies a selection of text and then pastes it into a sheet in another workbook.

For ease, lets call the two workbooks a user and master. The code is all in the 'user' workbook, when I step through the 'Enter and Store' macro I get to the row where the 'master' workbook opens without issue but then with the next press of F8 it jumps back to the Sub Enter_and_store() line and then subsequent F8's run through all of the code again rather than selecting the 'DATA' sheet. If I manually move the process to the point where it selects the 'DATA' sheet, the rest of the process works perfectly. The last part of the code using the FORM sheet is back in the 'user' workbook again.

Can anyone help please?

VBA Code:
Sub Enter_and_store()
'
    Range("C2:C6").Select
    Selection.Copy
Set wbk = Workbooks.Open("Master workbook filepath")
    Sheets("DATA").Select
    Range("A1048576").Select
    Selection.End(xlUp).Select
    ActiveCell.Offset(1).Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    ActiveWorkbook.Save
    ActiveWorkbook.Close
    
    Sheets("FORM").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("C2").Select
End Sub
 
I've never seen something like this before, apart from expected or intended recursion, of course.
I'm willing to examine your issue, provided you don't change anything in the current code in your workbook.
If you agree upload your workbook to a file share site like WeTransfer or DropBox and post a link within this thread.
Thanks for the offer and sorry for the delay.

I've managed to sort it out, the workbook that it was opening (the 'master') was in .xlsm format and that appears to have been causing the issue. As it happened, because of how is written now, I no longer needed the macros in the master workbook so I've saved it as a .xlsx file and it's working fine.
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Glad it's sorted and thank you for the follow-up (y)
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,928
Members
449,094
Latest member
teemeren

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