ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   problems when moving code from Macro to Command button on sheet (https://www.excelbanter.com/excel-programming/381360-re-problems-when-moving-code-macro-command-button-sheet.html)

merjet

problems when moving code from Macro to Command button on sheet
 
You could have the CommandButton call the macro that works.

The problem is likely this line:

Set myC = Range("I6:I233").Find(What:="", LookAt:=xlWhole)

Excel takes the range to be on whatever the active sheet is.

If you change it to:

Set myC = Worksheets.("Printout").Range("I6:I233").Find(What :="",
LookAt:=xlWhole)

the range is better specified.

HTH,
Merjet


merjet

problems when moving code from Macro to Command button on shee
 
I didn't get a runtime error on the modified line:
Set myC = Worksheets("Printout").Range("I6:I233").Find(What: ="",
LookAt:=xlWhole)

However, I did on this one:
Range(myC, Range("I233")).Resize(, 5).Delete Shift:=xlUp

until I also modified it to:
Worksheets("Printout").Range(myC,
Worksheets("Printout").Range("I233")).Resize(, 5).Delete Shift:=xlUp

HTH,
Merjet



All times are GMT +1. The time now is 12:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com