Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Karl
 
Posts: n/a
Default Column number of last column containing a number

Trying to figure a formula that will give me the column number of the last
column with data in a range. This is a sliding entry row where there may be
blanks at the begining and middle of the range.

Range is b26:m26 and may be as below:
0 0 1 1 0 1 1 0 0 0 0 0

I am looking to get colum 8 for use in an OFFSET lookup to other data in the
column.

I have tried no end of some of the suggested formulas in this forum but have
not gotten there yet.

Thank you
--
Karl
  #2   Report Post  
JMB
 
Posts: n/a
Default

The only way I know to do it is to use VBA. Hit Alt-F11, right click on your
project (VBA Project (xxxxxxx.xls)) select Insert/Module and paste the
following function in the code window.

Function LastColumn(rng As Range) As Long
Dim ISect As Range
On Error Resume Next

LastColumn = 0
Set ISect = Intersect(rng, rng.Parent.UsedRange)
For Each x In ISect
If (x.Value < "" Or x.HasFormula) And _
x.Column LastColumn Then _
LastColumn = x.Column
Next x

End Function


If you wanted to treat 0's as empty cells you could change

If (x.Value < "" Or x.HasFormula) And _
x.Column LastColumn Then _

To

If (x.Value < "" Or x.HasFormula) And _
x.Column LastColumn And x.Value < 0 Then _


To get the next empty cell for a range you would enter =Lastcolumn(x)+1
where x is the range you want evaluated (b26:m26??).


"Karl" wrote:

Trying to figure a formula that will give me the column number of the last
column with data in a range. This is a sliding entry row where there may be
blanks at the begining and middle of the range.

Range is b26:m26 and may be as below:
0 0 1 1 0 1 1 0 0 0 0 0

I am looking to get colum 8 for use in an OFFSET lookup to other data in the
column.

I have tried no end of some of the suggested formulas in this forum but have
not gotten there yet.

Thank you
--
Karl

  #3   Report Post  
Domenic
 
Posts: n/a
Default

Try...

=LOOKUP(2,1/(26:26=1),COLUMN(26:26))

....confirmed with just ENTER

OR

=MATCH(2,1/(26:26=1))

....confirmed with CONTROL+SHIFT+ENTER, not just ENTER

Hope this helps!

In article ,
"Karl" wrote:

Trying to figure a formula that will give me the column number of the last
column with data in a range. This is a sliding entry row where there may be
blanks at the begining and middle of the range.

Range is b26:m26 and may be as below:
0 0 1 1 0 1 1 0 0 0 0 0

I am looking to get colum 8 for use in an OFFSET lookup to other data in the
column.

I have tried no end of some of the suggested formulas in this forum but have
not gotten there yet.

Thank you

  #4   Report Post  
Karl
 
Posts: n/a
Default

JMB,

Thanks. Sadly I have never used VBA and on the workbook I can only use
formulas to get there. It is not mine and has a LOT of macros that I would
rather not chance messing up.

Karl
--
Karl


"JMB" wrote:

The only way I know to do it is to use VBA. ......

  #5   Report Post  
Karl
 
Posts: n/a
Default

Domenic,

This is the one. Works exactly as I needed in all my tests this AM.

Thank you.

Karl

--
Karl


"Domenic" wrote:

Try...




  #6   Report Post  
Karl
 
Posts: n/a
Default

After some more testing I had to change the comparison from =1 to <"". The
range I am checking is computed and can be a 0 or higher. The formula returns
a "blank" if no values found.

Thanks again Domenic.
--
Karl


  #7   Report Post  
David McRitchie
 
Posts: n/a
Default

Hi Karl,
stalemate? Wait a minute you're not trying to place a formula
just get the row. Perhaps it is possible.

see formulas in
Lastcell, Reset Last Used Cell
Some Worksheet Function coding for lastcell in column (#formulas)
http://www.mvps.org/dmcritchie/excel...l.htm#formulas
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Karl" wrote in message ...
JMB,

Thanks. Sadly I have never used VBA and on the workbook I can only use
formulas to get there. It is not mine and has a LOT of macros that I would
rather not chance messing up.

Karl
--
Karl


"JMB" wrote:

The only way I know to do it is to use VBA. ......



  #8   Report Post  
Harlan Grove
 
Posts: n/a
Default

Karl wrote...
Trying to figure a formula that will give me the column number of the last
column with data in a range. This is a sliding entry row where there may be
blanks at the begining and middle of the range.

Range is b26:m26 and may be as below:
0 0 1 1 0 1 1 0 0 0 0 0

I am looking to get colum 8 for use in an OFFSET lookup to other data in the
column.

....

The following array formula is certain to work.

=MAX(IF(1-ISBLANK(B26:M26),COLUMN(B26:M26)))

  #9   Report Post  
David McRitchie
 
Posts: n/a
Default

sorry didn't notice the other branches of this thread.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
find the largest number in column Jack Excel Discussion (Misc queries) 5 April 13th 05 03:40 PM
how to set up a column in excel so it can auto number Excel questions Excel Discussion (Misc queries) 2 March 10th 05 08:35 AM
How do I sort a column a unique number? ChelleA Excel Worksheet Functions 7 February 19th 05 10:38 AM
Write formula to add "1" to each number in a column GrannyLib Excel Worksheet Functions 3 January 11th 05 07:09 PM
how do I find an average number of specific words in a column cashgrfx New Users to Excel 7 January 6th 05 04:44 PM


All times are GMT +1. The time now is 02:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"