Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The excel.worksheet function MATCH(Person,{NameList},0) will return the
index number of the name supplied: e.g. Janet would return 4 Example: In Excel - Name the worksheet "theName" - Name the list of names "NameList" - Assume you want ages placed one col to right of names Using this from VBA Sub Test() FillList "Fred", 42 FillList "Janet", 38 FillList "Brian", 22 End Sub Sub FillList(strName, lngAge) Const BAD_MATCH As String = "Unable to get the Match" Const EXACT_MATCH As Long = 0 Dim mySheet As Excel.Worksheet Dim myRange As Excel.Range Dim ListIndex As long Set mySheet = Excel.ActiveWorkbook.Worksheets("theSheet") Set myRange = mySheet.Range("NameList") On Error Resume Next ' Without this code will fall over if strName is not in the list ListIndex = Excel.WorksheetFunction.Match(strName, myRange, EXACT_MATCH) If Err.Number = 0 Then myRange.Cells(ListIndex, 2).value = lngAge ElseIf Left(Err.Description, 23) = BAD_MATCH Then MsgBox "Name: " & strName & " not found" Else 'Unexpected Error MsgBox "Error Number: " & Err.Number & vbCrLf & _ "Description: " & Err.Description End If On Error GoTo 0 Set mySheet = Nothing Set myRange = Nothing End Sub HTH "Tod" wrote in message ... | Okay, I'm going to try something new, so everybody duck!! | | I want to have an array that already has one dimension | filled in, then have the second dimension filled in at | run time. So if the first dimension is: | | Earl | Larry | Fred | Janet | Carrie | | I want to add values based on the name. The values will | not always come in the same order as the names. Is there | a way that I can "search" the array for the name and then | add the value next to the match? | | tod | | | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Array: Counting multiple values within array | Excel Worksheet Functions | |||
Adding numerical values based on multiple values in another column | Excel Worksheet Functions | |||
Use array to return array of values | Excel Worksheet Functions | |||
Convert values in a variant array to integer values | Excel Programming | |||
Adding an Array | Excel Programming |