Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Need to identify a column within a range that meets criteria

I have 2 wkshts W1 & W2. From W1 I need to query a range (D1:Z1) in W2 to
find the column that contains the value that matches to W1!A1.

This should be so simple but like Thomas Edison I now know 1000 ways that
won't work.

Thanks,
Steve
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Need to identify a column within a range that meets criteria

Maybe something like this:

Option Explicit
Sub testme()

Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim myCell As Range
Dim myRng As Range
Dim res As Variant

Set WS1 = Worksheets("sheet1")
Set WS2 = Worksheets("sheet2")

Set myCell = WS1.Range("a1")

With WS2
Set myRng = .Range("a1:Z1")
End With

res = Application.Match(myCell.Value, myRng, 0)

If IsError(res) Then
MsgBox "no match, the board goes back"
Else
MsgBox res & vbLf & myRng(res).Address
End If

End Sub



stebro wrote:

I have 2 wkshts W1 & W2. From W1 I need to query a range (D1:Z1) in W2 to
find the column that contains the value that matches to W1!A1.

This should be so simple but like Thomas Edison I now know 1000 ways that
won't work.

Thanks,
Steve


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Need to identify a column within a range that meets criteria

Thanks Dave - this works. The one thing that would be better is if I could
isolate just the column. Once I have the column I want to pass that to
another function. I'll work on it some more but now I have to give up my
coding to go to a dumb-old wedding :)

I'll be online later to let you know how things are going.

Steve

"Dave Peterson" wrote:

Maybe something like this:

Option Explicit
Sub testme()

Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim myCell As Range
Dim myRng As Range
Dim res As Variant

Set WS1 = Worksheets("sheet1")
Set WS2 = Worksheets("sheet2")

Set myCell = WS1.Range("a1")

With WS2
Set myRng = .Range("a1:Z1")
End With

res = Application.Match(myCell.Value, myRng, 0)

If IsError(res) Then
MsgBox "no match, the board goes back"
Else
MsgBox res & vbLf & myRng(res).Address
End If

End Sub



stebro wrote:

I have 2 wkshts W1 & W2. From W1 I need to query a range (D1:Z1) in W2 to
find the column that contains the value that matches to W1!A1.

This should be so simple but like Thomas Edison I now know 1000 ways that
won't work.

Thanks,
Steve


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Need to identify a column within a range that meets criteria

This portion:

MsgBox res & vbLf & myRng(res).Address

Showed the index into the lookup range and it showed the address of that cell
that matched.

If you want just the column:

MsgBox myRng(res).column



stebro wrote:

Thanks Dave - this works. The one thing that would be better is if I could
isolate just the column. Once I have the column I want to pass that to
another function. I'll work on it some more but now I have to give up my
coding to go to a dumb-old wedding :)

I'll be online later to let you know how things are going.

Steve

"Dave Peterson" wrote:

Maybe something like this:

Option Explicit
Sub testme()

Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim myCell As Range
Dim myRng As Range
Dim res As Variant

Set WS1 = Worksheets("sheet1")
Set WS2 = Worksheets("sheet2")

Set myCell = WS1.Range("a1")

With WS2
Set myRng = .Range("a1:Z1")
End With

res = Application.Match(myCell.Value, myRng, 0)

If IsError(res) Then
MsgBox "no match, the board goes back"
Else
MsgBox res & vbLf & myRng(res).Address
End If

End Sub



stebro wrote:

I have 2 wkshts W1 & W2. From W1 I need to query a range (D1:Z1) in W2 to
find the column that contains the value that matches to W1!A1.

This should be so simple but like Thomas Edison I now know 1000 ways that
won't work.

Thanks,
Steve


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Need to identify a column within a range that meets criteria

Thanks so much - I got it! Thanks for your support of this newsgroup!

steve



"Dave Peterson" wrote:

This portion:

MsgBox res & vbLf & myRng(res).Address

Showed the index into the lookup range and it showed the address of that cell
that matched.

If you want just the column:

MsgBox myRng(res).column



stebro wrote:

Thanks Dave - this works. The one thing that would be better is if I could
isolate just the column. Once I have the column I want to pass that to
another function. I'll work on it some more but now I have to give up my
coding to go to a dumb-old wedding :)

I'll be online later to let you know how things are going.

Steve

"Dave Peterson" wrote:

Maybe something like this:

Option Explicit
Sub testme()

Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim myCell As Range
Dim myRng As Range
Dim res As Variant

Set WS1 = Worksheets("sheet1")
Set WS2 = Worksheets("sheet2")

Set myCell = WS1.Range("a1")

With WS2
Set myRng = .Range("a1:Z1")
End With

res = Application.Match(myCell.Value, myRng, 0)

If IsError(res) Then
MsgBox "no match, the board goes back"
Else
MsgBox res & vbLf & myRng(res).Address
End If

End Sub



stebro wrote:

I have 2 wkshts W1 & W2. From W1 I need to query a range (D1:Z1) in W2 to
find the column that contains the value that matches to W1!A1.

This should be so simple but like Thomas Edison I now know 1000 ways that
won't work.

Thanks,
Steve

--

Dave Peterson


--

Dave Peterson

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
Populate worksheet with data that meets date range criteria P0llyW0G Excel Worksheet Functions 3 September 28th 08 10:01 PM
Automatically hide column or row if a cell value meets criteria [email protected] Excel Worksheet Functions 3 June 10th 08 10:18 PM
RANGE EXCEL copy cell that meets criteria in a range confused Excel Worksheet Functions 3 March 27th 08 01:41 PM
How do I count in column A when it meets all criteria in three col dereksmom Excel Worksheet Functions 2 November 9th 06 04:37 PM
Formula to return ADDRESS of cell in range that meets criteria Christie Excel Worksheet Functions 1 March 4th 05 11:13 PM


All times are GMT +1. The time now is 05:42 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"