Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default How to use Index function in coding macro?

Does anyone have any suggestions on how to use index function in coding macro?

myCell.Offset(0, 2).Value =
Index(B:B [under Temp worksheet],match("Industry",A:A [under Temp
worksheet],0))

Does anyone have any suggestions?
Thanks in advance for any suggestions
Eric
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default How to use Index function in coding macro?

Eric,

The workaheet formula
=INDEX(B1:B9,MATCH(A1,Sheet2!D1:D9,FALSE),1)
can be used in macro like this

Lvalue = Sheets("Sheet1").Range("A1").Value
Set IRange = Sheets("Sheet1").Range("B1:B9")
Set Vrange = Sheets("Sheet2").Range("D1:D9")
Set Mycell = Sheets("Sheet2").Range("D1")

Mycell.Offset(0, 2).Value = Application.WorksheetFunction.Index _
(IRange, Application.WorksheetFunction.Match(Lvalue, Vrange, False), 1)

Mike

"Eric" wrote:

Does anyone have any suggestions on how to use index function in coding macro?

myCell.Offset(0, 2).Value =
Index(B:B [under Temp worksheet],match("Industry",A:A [under Temp
worksheet],0))

Does anyone have any suggestions?
Thanks in advance for any suggestions
Eric

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default How to use Index function in coding macro?

There are just a handful of worksheet functions that can be called directly
from 'Application' more efficiently than from 'WorksheetFunction', eg Index
and Match in the following context -

Sub Test()
Dim r1 As Range, r2 As Range, r3 As Range
Dim LookUpVal As Variant

SampleData
Set r1 = Range("A1:A10")
Set r2 = Range("B1:B10")
Set r3 = Range("C1")

For i = 1 To 10
LookUpVal = i
Cells(i, 3) = i
Set r3 = Cells(i, 4)

With Application
r3.Value = .Index(r2, .Match(LookUpVal, r1, 0))
End With
Next

End Sub

Sub SampleData()
Dim i As Long
For i = 1 To 10
Cells(1, 1) = Int(Rnd() * 11)
Cells(i, 2) = Chr(64 + i)
Next
End Sub

There's a second advantage in bypassing 'WorkSheetFunction' in the above -
if there is no match an error value is returned rather than the code
breaking due to error.

Regards,
Peter T


"Eric" wrote in message
...
Does anyone have any suggestions on how to use index function in coding

macro?

myCell.Offset(0, 2).Value =
Index(B:B [under Temp worksheet],match("Industry",A:A [under Temp
worksheet],0))

Does anyone have any suggestions?
Thanks in advance for any suggestions
Eric



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 for index/match function [email protected] Excel Programming 7 April 28th 07 07:38 PM
coding an anagram function N Ramsay Excel Programming 19 November 9th 06 07:56 PM
Implant macro coding into ASP coding Sam yong Excel Programming 5 September 15th 05 10:37 AM
Coding in VLOOKUP function JC[_8_] Excel Programming 0 January 13th 04 09:02 PM


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