Ottsel
Board Regular
- Joined
- Jun 4, 2022
- Messages
- 174
- Office Version
- 365
- Platform
- Windows
I'm using the following code before running my script to help cover any errors, as people sometimes add spaces at the end of titles causing my macro to crash
so, before running I was attempting to make sure the sheet - which the name never changes - would be selected before executing to avoid it running on the wrong sheet.
If I remove the "Sheets("Sheet1").select" code it'll run fine, and if I use that code on its own macro it also runs fine.
Here's the error pop-up I receive when its added before the application.Trim(r)
so, before running I was attempting to make sure the sheet - which the name never changes - would be selected before executing to avoid it running on the wrong sheet.
VBA Code:
Sub MrExcelExample()
Dim r As Range: Set r = Rows("8:9")
Sheets("Sheet1").Select
ActiveSheet.Unprotect
r.Value = Application.Trim(r)
End Sub
If I remove the "Sheets("Sheet1").select" code it'll run fine, and if I use that code on its own macro it also runs fine.
Here's the error pop-up I receive when its added before the application.Trim(r)