I have a VBS script that copies an existing sheet and I need to clear a dynamic range of cells (depends on the particular excel workbook opened)
I am able to clear the range when it is hard coded:
Set xl = CreateObject("Excel.application")
fso.CopyFile strFileSelect, fso.GetParentFolderName(strFileSelect) & "\Newversion.xlsm"
wshShell.Run """" & fso.GetParentFolderName(strFileSelect) & "\Newversion.xlsm"""
xl.Application.Sheets("Auto").Range("E15:BP142").ClearContents
but get errors when I try
xl.Application.Sheets("Auto").Range(Cells(15, 5), Cells(142, 67)).ClearContents
Actually, I ultimately want to clear the range based on UBound of two arrays for the Range, something like:
xl.Application.Sheets("Auto").Range("E15", .Cells((UBound(ArrayText)+1), (((UBound(ArrayStepText) + 1) * 2) + 5))).ClearContents
I have tried also using cells instead of .cells, tried
set r = Range("E15", Cells(142,67))
and clearing r, that does not work either.
I also can't use xlUp or something like that as there are hidden and protected cells after my array range
There is a similar question
VBS for excel: Using a script variable in Range selection
but I cannot use the rebuilding of the string as I don't know the column letter that it ends with and would have to make a look-up table to determine the column letters from the UBound of the array and that number could go to 128.
Surely there is an easier/ more efficient way?
Thanks
CellsandRangeobjects. Get a reference to the worksheet and use fully qualified references.