I am relatively new to Scripting in general, and need help with determining the LETTER of the last column used in a VBScript. The CVS file I am reading in the VBScript has data in columns A thru F. Therefore, want to figure out how to get the value of "F" returned (to be used later in the script). Most google searches return how to do it in VBA, but not VBScript. I have tried several of the googled "suggestions", but nothing has worked.
Here's my script's set up:
Set fso = CreateObject("Scripting.FileSystemObject")
file = PathAndFileName.csv
With CreateObject("Excel.Application")
Set WB = .Workbooks.Open(file)
Suggested, but failed, attempts to get the letter value of the last column used:
1. LastColumn = WB.ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
2. LastColumn = WB.ActiveSheet.UsedRange.Column + WB.ActiveSheet.UsedRange.Columns.Count - 1
3. LastColumn = WB.ActiveSheet.Columns.Cells(1, Columns.Count).End(xlToLeft).Column
4. LastColumn = WB.ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column
5. LastColumn = Split(WB.ActiveSheet.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Cells.Address(1, 0), "$")(0)
6. LastColumn = WB.ActiveSheet.UsedRange.Column
Could someone please enlighten me on VBScript code that would actually work to return the LETTER value of the last column used?
Thanks....
Here's my script's set up:
Set fso = CreateObject("Scripting.FileSystemObject")
file = PathAndFileName.csv
With CreateObject("Excel.Application")
Set WB = .Workbooks.Open(file)
Suggested, but failed, attempts to get the letter value of the last column used:
1. LastColumn = WB.ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
2. LastColumn = WB.ActiveSheet.UsedRange.Column + WB.ActiveSheet.UsedRange.Columns.Count - 1
3. LastColumn = WB.ActiveSheet.Columns.Cells(1, Columns.Count).End(xlToLeft).Column
4. LastColumn = WB.ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column
5. LastColumn = Split(WB.ActiveSheet.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Cells.Address(1, 0), "$")(0)
6. LastColumn = WB.ActiveSheet.UsedRange.Column
Could someone please enlighten me on VBScript code that would actually work to return the LETTER value of the last column used?
Thanks....