Run-time error 9 after copying a macro to a new project in VBA

Copper Contributor

I have a very simple macro as below to run a UserForm (formHygiene) in VBA. It works fine in one file.

Capture1.JPG

I wanted to use it for other Excel file and copied the macro and the UserForm to other (by dragging them into a new VBA Project in VBA). Then when I ran the macro in the new Excel, I am getting a "Run-time error 9: Subscript out of range". When I tried to debug, it points to the line "formHygiene.Show" in the macro. So I think the error can be due to the new file not seeing the UserForm (formHygiene) somehow. But the UserForm is shown for the new one, as you see in the screenshot below. Can anyone tell me why I am getting this error?

 

Capture2.JPG

Thanks!

David

1 Reply

@seolac

 

Hi,

 

I've tried to reproduce that, but I didn't see any error!

If the new workbook has a different structure, so it's possible that the code in the UserForm refers to something missing.

 

Please watch this video to learn more about the Run-time error 9 and its common reasons.

 

Hope that helps