When asking help about an error message, always indicate the line of code where it is occurring. I do not see an obvious cause of the error you quoted, and do not have your file to be able to run a test. Can you indicate the line, or attach your file?
Also, I will bet that your declarations do not do what you think they are doing. For example,
does not declare four variables as Integer. It declares filledrowcount as Integer, and defaults all the others to Variant. Please see this excellent page on declarations.
This line of code works perfectly well but is deceiving in intent:
A much cleaner and obvious test would be
Using ActiveSheet unnecessarily can introduce bugs that are hard to diagnose. In this case you are always using Worksheets("Sheet1"), so there is no need to active it and refer to ActiveSheet. I recommend you modify your code as follows:
Bookmarks