Cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

last column used in a csv or excel file?

Gears Phenom Gears Phenom
Gears Phenom

To all

 

I have an NX program which deals with csv files. All the files created during the process are merged into 1 excel file.

I‘d like to check how may column of data are in the csv file being processed (to create the correct offset when merging the data)

What is the correct syntax to figure out the last column being used start in cell A1? I had the info somewhere but cannot find it. Gettign old I guess !

 

If the file has 3 columns of data then I need to return column 3!

 

Thanks

Regards

 

 

 

Production: NX.CAE 9.0.3.4, NX.CAE 10.0.2.6
Development: VB.NET (amateur level !)
2 REPLIES

Re: last column used in a csv or excel file?

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Something like this?

 

        Const xlDown As Long = -4121
        Const xlUp As Long = -4162
        Const xlToRight As Long = -4161
        Const xlMultiply As Long = 4
        Const xlPasteAll As Long = -4104

        objExcel.visible = True

        Dim LastRow As Integer
        Dim LastColumn As Integer

        LastRow = objWorksheet.Range("A65000").End(xlUp).Row
        LastColumn = objWorksheet.Range("A1").End(xlToRight).Column

I can post the full code if necessary, this bit just sets up the Excel constants (if you do not have an author license and cannot reference the Excel library directly) and shows the calls to get the last column and row.

Re: last column used in a csv or excel file?

Gears Phenom Gears Phenom
Gears Phenom
Thanks. You've already provided it to me !!! I just can't remember where I archived it!
Production: NX.CAE 9.0.3.4, NX.CAE 10.0.2.6
Development: VB.NET (amateur level !)