Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9060349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:12:23+00:00 2026-06-16T15:12:23+00:00

Consider the below matrix: Col1 Col2 Col3 Col4 Col5 Col6 Col7 R1 x x

  • 0

Consider the below matrix:

    Col1    Col2    Col3    Col4    Col5    Col6    Col7
R1   x       x                        x
R2           x                x              x
R3                                                    x
R4           x        x       x
R5                                    x

Now using VBScript or ADO whichever will it be possible to find the distance of the last element of each row? Defination of distance distance is nothing but the count of number of cells after which the last element is placed in the given matrix. for e.g say –

  • Dist(R1)=5

  • Dist(R4)=4 like wise

I tried the below:

Option Explicit

Dim ArrayListTaskDetails : Set ArrayListTaskDetails = CreateObject("System.Collections.ArrayList")
Dim i,colcount

i=2
Do while i < = objExcel1.Application.WorksheetFunction.CountA(ob.Rows(1))

colcount=objExcel1.Application.WorksheetFunction.CountA(ob.Rows(i))
ArrayListTaskDetails.Add(colcount)

i=i+1
Loop

ArrayListTaskDetails.Sort()
i=ArrayListTaskDetails.Count
MsgBox("HighestColumnNumner:" & ArrayListTaskDetails(i-1))

But it is not working,as couldn’t handle the in between blanks.

Thnaks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:12:24+00:00Added an answer on June 16, 2026 at 3:12 pm

    Another way… Using Formulas in VBSCRIPT

    Dim oXLApp, oXLWb, oXLWs
    
    Set oXLApp = CreateObject("Excel.Application")
    
    '~~> Show Excel
    oXLApp.Visible = True
    
    '~~> Open files (Change as applicable)
    Set oXLWb = oXLApp.Workbooks.Open("C:\MyFile.xlsx")
    Set oXLWs = oXLWb.Sheets(1)
    
    Dim lRow, i, tmp
    
    With oXLWs
        lRow = .Range("A" & .Rows.Count).End(-4162).Row
    
        For i = 2 To lRow
            tmp = oXLApp.Evaluate("=ADDRESS(ROW(A" & i & "),MATCH(INDEX($" & i _
            & ":$" & i & ",MAX(IF($A" & i & ":$K" & i & "<>"""",COLUMN($A" & i _
            & ":$K" & i & ")))),A" & i & ":K" & i & "),1)")
    
            MsgBox .Range("A" & i).Value & " :- " & .Range(tmp).Column - 1
        Next
    End With
    

    Screenshot

    enter image description here

    Followup

    As per the request

    Dim oXLApp, oXLWb, oXLWs
    
    Set oXLApp = CreateObject("Excel.Application")
    
    '~~> Hide Excel
    oXLApp.Visible = True
    
    '~~> Open files
    Set oXLWb = oXLApp.Workbooks.Open("C:\MyFile.xlsx")
    Set oXLWs = oXLWb.Sheets(1)
    
    Dim lRow, i, tmp, MyArray, ColNo, ReturnName
    
    With oXLWs
        lRow = .Range("A" & .Rows.Count).End(-4162).Row
    
        ColNo = .Columns.Count
    
        ReturnName = Split(.Cells(, ColNo).Address, "$", -1,1)(1)
    
        For i = 2 To lRow
            tmp = oXLApp.Evaluate("=ADDRESS(ROW(A" & i & "),MATCH(INDEX($" & i _
            & ":$" & i & ",MAX(IF($A" & i & ":$" & ReturnName & i & _
            "<>"""",COLUMN($A" & i & ":$" & ReturnName & i & ")))),A" & _
            i & ":" & ReturnName & i & "),1)")
    
            msgbox .Range("A" & i).Value & " :- " & .Range(tmp).Column - 1
        Next
    End With
    

    More Followup

    Option Explicit
    
    Dim oXLApp, oXLWb, oXLWs
    Dim lRow, i, tmp, MyArray, ColNo, ReturnName
    
    Set oXLApp = CreateObject("Excel.Application")
    
    '~~> Hide Excel
    oXLApp.Visible = True
    
    '~~> Open files
    Set oXLWb = oXLApp.Workbooks.Open("C:\MyFile.xlsx")
    
    '~~> Set the Sheet 1 as sheet1
    Set oXLWs = oXLWb.Sheets(1)
    
    With oXLWs
        '~~> Get the last row in the worksheet
        lRow = .Cells.Find("*", .Range("A1"), -4123, 2, 1, 2).Row
    
        '~~> Get the total col count
        ColNo = .Columns.Count
    
        '~~> This will return the column name from column number
        ReturnName = Split(.Cells(, ColNo).Address, "$", -1, 1)(1)
    
        For i = 1 To lRow
            '~~> We are using the Evaluate to calculate the formula
            '~~> which will find our result
            tmp = oXLApp.Evaluate("=ADDRESS(ROW(A" & i & "),MATCH(INDEX($" & i _
            & ":$" & i & ",MAX(IF($A" & i & ":$" & ReturnName & i & _
            "<>"""",COLUMN($A" & i & ":$" & ReturnName & i & ")))),A" & _
            i & ":" & ReturnName & i & "),1)")
    
            '~~> This will return the column number
            MsgBox "Last Col in Row " & i & " is " & .Range(tmp).Column
        Next
    End With
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

virtual function resolution happens with pointer/reference and not with object. Now consider below example:
Consider the below. #include <string> using std::string; string middle_name () { return Jaan; }
Consider the below struts Action class in which, I am using a StringBuilder variable
Is int a class ? Please consider below code #includeiostream using namespace std; class
I am using DateTime module. however it is providing wrong time. Please consider below
Consider the below String String names = Bharath-Vinayak-Harish-Punith I want to get output in
Consider the below: public class DependencyA {} public class DependencyB {} public class DependencyC
Consider the below situation I have a database table as below user_id user_rank ------------------
Let's consider the below example. There, I have: target MAIN calls target t and
Consider the script below. It will launch two subprocesses, each one a CherryPy app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.