If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Get number of columns

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-15-04, 11:35
millyb millyb is offline
Registered User
 
Join Date: Apr 2004
Posts: 1
Get number of columns

I am using Perl/Win32::OLE, but I can't figure out how to get the number of columns in a row. I have an EXCEL worksheet that has a different number of columns in each row and I want to access the third column from the end. Is there any way to get the number of columns in each row. Thank you!

melissa
Reply With Quote
  #2 (permalink)  
Old 04-15-04, 12:03
shades shades is offline
Registered User
 
Join Date: Oct 2003
Posts: 1,091
Perhaps these might help you get started: These are UDFs (by J. Walkenbach)

Code:
Function LASTINCOLUMN(rng As Range)
    Dim WorkRange As Range
    Dim i As Integer, CellCount As Integer
    Application.Volatile
    Set WorkRange = rng.Columns(1).EntireColumn
    Set WorkRange = Intersect(WorkRange.Parent.UsedRange, _
       WorkRange)
    CellCount = WorkRange.Count
    For i = CellCount To 1 Step -1
        If Not IsEmpty(WorkRange(i)) Then
            LASTINCOLUMN = WorkRange(i).Value
            Exit Function
        End If
    Next i
End Function
Code:
Function LASTINROW(rng As Range) As Variant
    Dim WorkRange As Range
    Dim i As Integer, CellCount As Integer
    Application.Volatile
    Set WorkRange = rng.Rows(1).EntireRow
    Set WorkRange = Intersect(WorkRange.Parent.UsedRange, _
      WorkRange)
    CellCount = WorkRange.Count
    For i = CellCount To 1 Step -1
        If Not IsEmpty(WorkRange(i)) Then
            LASTINROW = WorkRange(i).Value
            Exit Function
        End If
    Next i
End Function
__________________
old, slow, and confused
but at least I'm inconsistent!

Rich
(retired Excel 2003 user, 3/28/2008)

How to ask a question on forums
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On