Set rng = ws.Range("A1", ws.Range("A1").End(xlDown))
For each cl in rng
Getting Run-time error '1004':
Application-defined or object-defined error in
**Set rng = ws.Range("A1", ws.Range("A1").End(xlDown))**
Please help
Set rng = ws.Range("A1", ws.Range("A1").End(xlDown))
For each cl in rng
Getting Run-time error '1004':
Application-defined or object-defined error in
**Set rng = ws.Range("A1", ws.Range("A1").End(xlDown))**
Please help
Rory has already told you what the main problem with your code is.
I would recommend a slightly different approach to what you are trying to achieve.
Please note that
xlDown
should be avoided as much as possible. Consider the scenario where there is data only in cellA1
. In such a casexlDown
will select the entire Col A. The alternative is to find last row in Col A which has data and then create your range.And declare this at the top
And if you are sure that there will always be data in Col A then you can try this as well
And declare this at the top
I suspect you don't have a reference set to the Excel object library in which case
xlDown
has no value. Either use:or, preferably, define the constant yourself at the top of your module: