Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro help: VLOOKUP with conditions


Hi all. Say I have a sheet (sheet 1) that has this data:

Group ID Number
LMF1_bla AAAA 11111
LMF1_blu BBBB 33456
LMF2_gh KKKK 45456
LMF2_bla AAAA 22222


And then I have another sheet (sheet 2) with this data:

ID Number
AAAA


I basically want to VLOOKUP the Number for AAAA but only if it is part
of a Group that contains LMF1 in sheet 1. Can someone help me make a
macro for this task? Any help would be greatly appreciated.


--
uberathlete
------------------------------------------------------------------------
uberathlete's Profile: http://www.excelforum.com/member.php...o&userid=28388
View this thread: http://www.excelforum.com/showthread...hreadid=479763

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro help: VLOOKUP with conditions

Sub AAAA()
Dim rng As Range, rng1 As Range
Dim rng2 As Range, rng3
' rng3 holds "AAAA"
Set rng3 = Worksheets("Sheet2").Range("A1")
With Worksheets("Sheet1")
Set rng = .Range(.Cells(1, 2), _
.Cells(2, 2).End(xlDown))
End With
ebug.Print rng.Address
Set rng1 = rng.Find( _
What:=rng3.Value, _
After:=rng(1), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng1 Is Nothing Then
sAddr = rng1.Address
Do
If InStr(1, rng1.Offset(0, -1), _
"LMF1", vbTextCompare) Then
If rng2 Is Nothing Then
Set rng2 = rng1
Else
Set rng2 = Union(rng2, rng1)
End If
End If
Set rng1 = rng.FindNext(rng1)
Loop While rng1.Address < sAddr
If Not rng2 Is Nothing Then
' now work with rng2
rng2.Parent.Activate
rng2.Select
Else
MsgBox "Nothing found"
End If
End If

End Sub

--
Regards,
Tom Ogilvy

"uberathlete"
wrote in message
...

Hi all. Say I have a sheet (sheet 1) that has this data:

Group ID Number
LMF1_bla AAAA 11111
LMF1_blu BBBB 33456
LMF2_gh KKKK 45456
LMF2_bla AAAA 22222


And then I have another sheet (sheet 2) with this data:

ID Number
AAAA


I basically want to VLOOKUP the Number for AAAA but only if it is part
of a Group that contains LMF1 in sheet 1. Can someone help me make a
macro for this task? Any help would be greatly appreciated.


--
uberathlete
------------------------------------------------------------------------
uberathlete's Profile:

http://www.excelforum.com/member.php...o&userid=28388
View this thread: http://www.excelforum.com/showthread...hreadid=479763



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro help: VLOOKUP with conditions


Thank Tom :) . Hmm .. unfortunately if it gives out an error in th
ebug.Print rng.Address portion. Is there any way to fix this

--
uberathlet
-----------------------------------------------------------------------
uberathlete's Profile: http://www.excelforum.com/member.php...fo&userid=2838
View this thread: http://www.excelforum.com/showthread.php?threadid=47976

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro help: VLOOKUP with conditions

Yes, remove that line. I guess when I went to delete it I only got the
first character. It was

Debug.Print rng.Address

but it is not needed.

--
Regards,
Tom Ogilvy

"uberathlete"
wrote in message
...

Thank Tom :) . Hmm .. unfortunately if it gives out an error in the
ebug.Print rng.Address portion. Is there any way to fix this?


--
uberathlete
------------------------------------------------------------------------
uberathlete's Profile:

http://www.excelforum.com/member.php...o&userid=28388
View this thread: http://www.excelforum.com/showthread...hreadid=479763



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro help: VLOOKUP with conditions


<please ignore


--
uberathlete
------------------------------------------------------------------------
uberathlete's Profile: http://www.excelforum.com/member.php...o&userid=28388
View this thread: http://www.excelforum.com/showthread...hreadid=479763

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
Vlookup with 2 Conditions Kathy - Lovullo Excel Discussion (Misc queries) 2 September 15th 09 04:08 PM
VLOOKUP with 2 Conditions al_ba Excel Worksheet Functions 3 September 22nd 08 01:20 AM
VLOOKUP with 2 conditions RSantos Excel Discussion (Misc queries) 5 June 26th 06 06:11 PM
Vlookup with 3 or more conditions LondonLion Excel Worksheet Functions 1 December 28th 05 04:02 PM
Vlookup using 2 conditions Jambruins Excel Discussion (Misc queries) 3 November 15th 05 02:15 PM


All times are GMT +1. The time now is 09:24 PM.

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"