I wrote a code in vbscript as below ,but when i run my script it is giving an error saying the “Range” is undefined. Can any help me here by saying what is the error?
For TaskCounter = 1 to 35
TaskRangeFrom="Task"&TaskCounter&" Start Date"
TaskRangeTo="Task"&(TaskCounter+1)&" Name"
objSheet6.Range(Range(TaskRangeFrom).Offset(,1), _
Range(TaskRangeTo).Offset(,-1)).EntireColumn.Delete
Next
Thanks in advance.
As @NickSlash mentioned yesterday, I doubt that you have given range names like
“Business Process ID” (containg spaces) to your columns. But as this may be
a version thing, I show you how to get a ‘whole column’ range object for a
column named “TaskB” (via the “define name” dialog):
To get a range for the second column by (column) number, use:
Please note: row and column numbers start with 1. So your “.Offset(,1)”
code looks very fishy; it may have caused the “Unknown runtime error”.
If you – as I suppose – wrote your column titles in the first row, you’ll
have to loop over the columns of that row and check the values:
If you want to experiment, insert those snippets into test code like:
Pics to give evidence: