Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Macro instead of lookup

How to make a macro which works same as hlookup?

Eg: I have some data in a different file and I need to get those to active
sheet. if value in range a1:z1 matches a1.value in active sheet then it
should get value from corresponing cloumn
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Macro instead of lookup

You can try

Worksheetfunction.HLookup

If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

How to make a macro which works same as hlookup?

Eg: I have some data in a different file and I need to get those to active
sheet. if value in range a1:z1 matches a1.value in active sheet then it
should get value from corresponing cloumn

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Macro instead of lookup

Adapt to suit

Sub hlookupa()
MsgBox Application.hlookup(Range("b5"), Range("a1:z1"), 1, 0)
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Kashyap" wrote in message
...
How to make a macro which works same as hlookup?

Eg: I have some data in a different file and I need to get those to active
sheet. if value in range a1:z1 matches a1.value in active sheet then it
should get value from corresponing cloumn


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Macro instead of lookup

can I have the full code pls
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro instead of lookup

set c = Rows(1).find(what:="abc",lookin:=xlvalues,lookat:= xlwhole)

then test fo c
if c is nothing then
msgbox("count not find abc")
else
msgbox("data found in column " & c.column)
end if

"Kashyap" wrote:

How to make a macro which works same as hlookup?

Eg: I have some data in a different file and I need to get those to active
sheet. if value in range a1:z1 matches a1.value in active sheet then it
should get value from corresponing cloumn



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Macro instead of lookup

WorksheetFunction.hlookup("abc",Range("a1:z1"), 1, 0)

OR try with INDEX and MATCH

Msgbox Application.Index(Range("A1:Z10"),1, _
Application.Match("abc", Range("A1:Z1"), 0))

If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

can I have the full code pls

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Macro instead of lookup

I'm getting type mismatch error
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Macro instead of lookup

The range is having numbers or text?

Just post back with how the data is arranged and your current code..

If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

I'm getting type mismatch error

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Macro instead of lookup

ColA ColB ColC ColD ColE ColF
Calvin Amy Andy Calvin Danie Greg
ABC GEF LMO GEF LMO
GEF LMO IJK LMO
LMO IJK IJK
IJK


In the above table, desiredoutput in ColA below Calvin

LMO
IJK

formula used
=HLOOKUP(A2,B2:F6,2)
=HLOOKUP(A2,B2:F6,3)
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Macro instead of lookup

you have a look at the file at the below link

http://www.savefile.com/files/2116453


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Macro instead of lookup

Try this

Application.HLookup(Range("A2"),Range("B2:F6"),2)

OR

Application.Index(Range("B2:F6"),2,Application.Mat ch(Range("A2"),Range("B2:F2"),0))

If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

ColA ColB ColC ColD ColE ColF
Calvin Amy Andy Calvin Danie Greg
ABC GEF LMO GEF LMO
GEF LMO IJK LMO
LMO IJK IJK
IJK


In the above table, desiredoutput in ColA below Calvin

LMO
IJK

formula used
=HLOOKUP(A2,B2:F6,2)
=HLOOKUP(A2,B2:F6,3)

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro instead of lookup

Using a worksheet function where you can use a VBA function is inefficient.

RowCount = 2
Person = Range("A" & RowCount)
LastCol = Cells(RowCount, Columns.Count).End(xlToLeft).Column
Set LookupRange = Range(Range("B" & RowCount), Cells(2, LastCol))
Set c = Rows(RowCount).Find(what:=Person, _
LookIn:=xlValues, lookat:=xlWhole)
MsgBox (Person & " found at " & c.Address)


Try this

set c =

"Jacob Skaria" wrote:

Try this

Application.HLookup(Range("A2"),Range("B2:F6"),2)

OR

Application.Index(Range("B2:F6"),2,Application.Mat ch(Range("A2"),Range("B2:F2"),0))

If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

ColA ColB ColC ColD ColE ColF
Calvin Amy Andy Calvin Danie Greg
ABC GEF LMO GEF LMO
GEF LMO IJK LMO
LMO IJK IJK
IJK


In the above table, desiredoutput in ColA below Calvin

LMO
IJK

formula used
=HLOOKUP(A2,B2:F6,2)
=HLOOKUP(A2,B2:F6,3)

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Macro instead of lookup

Compilation error

Expected:=
  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro instead of lookup

Do you have two postings mixed up? Expected isn't showing up anywhere in tis
posting.

"Kashyap" wrote:

Compilation error

Expected:=

  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Macro instead of lookup

As Joel mentioned it may be inefficient. Since your original query was around
hookup try this one..from VBEimmediate window

?Application.HLookup(Range("A2"),Range("B2:F6"),2)


If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Compilation error

Expected:=



  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro instead of lookup

Application is still performing a worksheet function. You code is no
different with or without the APPLICATION.

"Jacob Skaria" wrote:

As Joel mentioned it may be inefficient. Since your original query was around
hookup try this one..from VBEimmediate window

?Application.HLookup(Range("A2"),Range("B2:F6"),2)


If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Compilation error

Expected:=

  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Macro instead of lookup

Joel, I understand it is a worksheet function and I have not mentioned in my
previous post that it is an *** alternative *** VBA function .

If this post helps click Yes
---------------
Jacob Skaria


"Joel" wrote:

Application is still performing a worksheet function. You code is no
different with or without the APPLICATION.

"Jacob Skaria" wrote:

As Joel mentioned it may be inefficient. Since your original query was around
hookup try this one..from VBEimmediate window

?Application.HLookup(Range("A2"),Range("B2:F6"),2)


If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Compilation error

Expected:=

  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Macro instead of lookup

Hi Jacob,

I'm now getting

compilation error
Method not valid without suitable object



"Jacob Skaria" wrote:

As Joel mentioned it may be inefficient. Since your original query was around
hookup try this one..from VBEimmediate window

?Application.HLookup(Range("A2"),Range("B2:F6"),2)


If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Compilation error

Expected:=

  #19   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Macro instead of lookup

using below code, it says data found in 2 columns, but not able to paste data
to a different row



"Joel" wrote:

set c = Rows(1).find(what:="abc",lookin:=xlvalues,lookat:= xlwhole)

then test fo c
if c is nothing then
msgbox("count not find abc")
else
msgbox("data found in column " & c.column)
end if

"Kashyap" wrote:

How to make a macro which works same as hlookup?

Eg: I have some data in a different file and I need to get those to active
sheet. if value in range a1:z1 matches a1.value in active sheet then it
should get value from corresponing cloumn

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
macro to lookup value and open tab based on lookup value brandyvine Excel Programming 3 December 16th 08 09:57 AM
MACRO TO LOOKUP AND SUM K[_2_] Excel Programming 3 April 18th 08 08:55 PM
Lookup macro gramps Excel Discussion (Misc queries) 3 September 14th 07 04:36 PM
Is it possible...lookup macro Haxer Excel Programming 5 August 4th 07 08:50 AM
Lookup macro? John Keturi Excel Programming 1 October 14th 04 06:30 AM


All times are GMT +1. The time now is 09:13 AM.

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

About Us

"It's about Microsoft Excel"