This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
When running a code to create a new "clean" copy of a worksheet (deleting the sheet code in the copy), I continue to get a "Run-time error '1004': Method 'Range' of object '_Global' failed"
The dialogue box does not give me an option to debug, so I am at a loss as to how to fix this. My usual google solution searching has lead to nothing useful since this is such a general error.
Any ideas as to what is triggering this error?
Sheets("ORIGINALPAGE").Select
Sheets("ORIGINALPAGE").Copy After:=Sheets(4)
Sheets("ORIGINALPAGE (2)").Name = "COPYOFORIGINAL"
Sheets("COPYOFORIGINAL").Unprotect
Sheets("COPYOFORIGINAL").Select
Columns("J:J").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Dim cntOfLines As Long
cntOfLines = Application.VBE.VBProjects(1).VBComponents("Sheet2").CodeModule.CountOfLines
Application.VBE.VBProjects(1).VBComponents("Sheet5").CodeModule.DeleteLines 1, cntOfLines
Sheets("COPYOFORIGINAL").Select
Columns("O:AR").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
End Sub
Thanks for any help or suggestions.
--
EDIT: Thank you to the users who offered to take a close look and help me solve this one.
Here is one solution that has proved successful from /u/sooka. I changed the last section to:
Columns("O:AR").Select
Application.EnableEvents = False
Selection.Delete Shift:=xlToLeft
Application.EnableEvents = True
While I had thought deleting the worksheet code would be enough, apparently it was not. Adding this disabled the event code and allowed the columns to be deleted.
Subreddit
Post Details
- Posted
- 4 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/vba/comment...