ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Lookup first/last column of record (https://www.excelbanter.com/excel-programming/407283-lookup-first-last-column-record.html)

Abrm

Lookup first/last column of record
 
Hello

I want to lookup the first and last column of a record.
It is a planning tool, in the columns are dates.in the records are tasks.
I would like to search all column in the record. The first column is the
begin date of my task, the last column is the end date of my task.

Can someone help me?

thanks



Mike H

Lookup first/last column of record
 
Hi,

I'm a bit confused about finding the first used column in a row, don't you
know where that is?

To find that last date in a row try this
=INDEX(1:1,MATCH(9.99999999999999E+307,1:1))
This is for row 1 so cjange to suit.

Mike

"Abrm" wrote:

Hello

I want to lookup the first and last column of a record.
It is a planning tool, in the columns are dates.in the records are tasks.
I would like to search all column in the record. The first column is the
begin date of my task, the last column is the end date of my task.

Can someone help me?

thanks



Rick Rothstein \(MVP - VB\)[_1399_]

Lookup first/last column of record
 
I want to lookup the first and last column of a record.
It is a planning tool, in the columns are dates.in the records are tasks.
I would like to search all column in the record. The first column is the
begin date of my task, the last column is the end date of my task.


Assuming you are looking for a VBA solution (given that you posted in the
programming newsgroup), you can use these two functions to get the
information you seek...

Function FindFirstDataCell(R As Range) As Range
Dim X As Long
For X = R.Column To R.Column + R.Count + 1
If Len(Cells(R.Row, X).Value) 0 Then
Set FindFirstDataCell = Cells(R.Row, X)
Exit For
End If
Next
End Function

Function FindLastDataCell(R As Range) As Range
Dim X As Long
For X = R.Column + R.Count + 1 To R.Column Step -1
If Len(Cells(R.Row, X).Value) 0 Then
Set FindLastDataCell = Cells(R.Row, X)
Exit For
End If
Next
End Function

Just pass in the range (for the row of interest) within your grid where the
dates get filled in; since a range is returned, you can get the information
about the first and last cell directly from the returned values. For
example...

Dim First As Range
Dim Last As Range
Set First = FindFirstDataCell(Range("D4:Q4"))
Set Last = FindLastDataCell(Range("D4:Q4"))
If Not First Is Nothing Then
Debug.Print "First Date: " & First.Value & " in column " & First.Column
End If
If Not Last Is Nothing Then
Debug.Print "Last Date: " & Last.Value & " in column " & Last.Column
End If

where I have assumed your dates are filled in from Column D through Column Q

Rick



All times are GMT +1. The time now is 06:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com