VBA bug - code exits sub before completion - no error message

stefsj

New Member
Joined
May 27, 2010
Messages
23
Hi,

I am a frequent reader of this forum and learned quite a lot from you guys so I hope you can help me in my current situation as well because I haven't found the answer anywhere.

I have a big file that I have been working with for a while. Many formulas, links between tabs and so on. Not many macro's. But the ones I have are for hiding and unhiding some of the columns. Until some recent modifications everything was working fine. But recently (and I don't know what might have caused it) the macro's start acting up. For example:
Sub Viewadj()
ActiveSheet.Unprotect
If Columns("AH:AM").Hidden = True Then
Columns("AH:AM").Hidden = False - stops after completing this step
Else:
Columns("AH:AM").Hidden = True - or this step
End If
ActiveSheet.Protect
End Sub

If I run this macro, as simple as it looks, once there is some action done on the sheet (the two lines in bold) the macro stops without any message. Simply is done. Similar thing happens here:
Sub ExportN()
Select Case MsgBox("...", vbYesNo, "...Results")
Case vbYes
j = 1
ActiveSheet.Unprotect ("Cr8y92Bq5")
Range(Cells(36, 143), Cells(162, 143)).ClearContents - exits
j = 36
For i = 36 To 162
As soon as the macro clears the contents of those cells it stops without a message.

The interesting thing - if I run these same codes in other worksheets within the same file, it works fine.

All my worksheet calls are blank so nothing there. But something clearly happens when I make a change to the sheet and can't figure out why and how to stop it.

Thank you in advance!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Welcome to the forum.:)

Do you make these observations by stepping through the code using F8, or just by observing the end results?

Do you have any event handlers in the project?
 
Upvote 0
Thanks for the quick response.

Initially seeing the end results, which caused me to do it with the F8.

If you refer to the worksheet calls like Change, Activate and so on, all of them are empty. I haven't done anything with them, but that was my first thought as well. But to make sure I am going to the write place - Select the Sheet in the VB Editor, then dropdown "Worksheet" and second drop down sends me to different events. Is this the correct place to look?
 
Upvote 0

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

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