Forum Discussion
waygar
Nov 10, 2022Brass Contributor
To run a macro on another excel sheet with a different number of rows
Hi, I recorded a macro but when I try to use it on another spreadsheet with a different number of rows I get Error 9. Help I am new to this.
HansVogelaar
Jan 11, 2023MVP
Yes, that requires a change to the code. Change the line
Set wbkClass = ThisWorkbook
to
Set wbkClass = Workbooks("Classf.xlsx")waygar
Jan 11, 2023Brass Contributor
Nope same error.
Runs perfectly if I remove Personal.XLSB from my XLSTART
Runs perfectly if I remove Personal.XLSB from my XLSTART
- waygarJan 11, 2023Brass ContributorOk I now know what the cause is - assigning a shortcut key to the macro.
Even with your code, assigning a shortcut key such as CTRL SHFT U makes the code only work if run twice. I don't know why! - HansVogelaarJan 11, 2023MVP
I cannot explain that.
P.S. This discussion has become very long and awkward to navigate.
If you have a new question unrelated to the current discussion, would you be so kind to start a new discussion? Thanks in advance.
- waygarJan 11, 2023Brass ContributorSorry Hans
I did have a typo and your code now works in PERSONAL.XLSB
Why my code needs the dual run is a mystery? - HansVogelaarJan 11, 2023MVP
In that case, I have no idea why it doesn't work, but you could try
Set wbkClass = ActiveWorkbookas in your original code.
- waygarJan 11, 2023Brass ContributorYes
- HansVogelaarJan 11, 2023MVP
Are you sure that your workbook is named Classf.xlsx and that it is open in Excel?