Excel get total number of columns

rohit.x07

New Member
How can i get the total number of columns in the excel. Also i want to know the column range.

Eg: in my excel there are 125 columns and sometimes it comes more, i want know the total columns in excel also want to know the last column range.

in the snapshot i want to know the highlighted column range DU.
Thanks in advance for your cooperation.
 

Attachments

  • Column.png
    174.3 KB · Views: 17

sivagelli

Well-Known Member
You need a code stage-

In the Excel VBO, add a new object lets call it Column Count. Here is my version of code, try and post back how it works-


The Flow of the Object is:

Have: Handle (Number), Success (Text), Message (Text) and LastColumn (Text) as Data Items on the Object page.
  1. Start: Inputs-
    • Handle
  2. Code Stage with below line of code-
  3. Decision Stage with Expression [Success]
    • Link Yes Path to End stage
    • No Path to Exception with Exception Type as blank and Exception Detail as "Failed at:" & [Message]
  4. End Stage Output is LastColumn
Code:
Try
LastColumn = Split(Getworkbook(Handle,nothing).Activesheet.cells.Find(What:="*", SearchOrder:=2, SearchDirection:=2).Cells.Address(1,0), "$")(0)
Success= True

Catch e As Exception
Success = False
Message = e.Message

End Try

Once you call this object from Process, you will get the last column name.
 
Top