Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default List of items in an array - VBA?

Hello

Excel 2003 query around VBA and how you access a Range

Consider two cols of data with people's favourite colour

A B
1) Fred Red
2) Sid Red
3) Bob Blue
4) Andy Reg
5) Steve Blue

What I want is to write the following
=funcWhoCol(A1:B5,"Blue")

The function will return a string containing the names of people whose
favourite colour matches the second parameter, in this case the strung
returned would be "Bob Steve"

I started to create a function and pass the range in as the first param
and the match string as the second but I can't find how to manipulate
the range in my function.

What I want is logically as shown below (although I have no idea about
how to do it so the code is nonsense)

function funcWhoCol is (inRange, inMatch)

for i_count = 1 to inRange.Cells.Count
if inRange(i_count) = inMatch then funcWhoCol = funcWhoCol +
inRange(i_count) + " "
next i_count

end function


Many thanks in advance
Craig

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default List of items in an array - VBA?

Maybe something like:

Option Explicit
Function FuncWhoCol(inRange As Range, inMatch As String) As String

Dim i_Count As Long
Dim myStr As String
Dim myCell As Range

'add as many validity checks as you can think of
If inRange.Areas.Count 1 Then
FuncWhoCol = "Too many Areas!"
Exit Function
End If

If inRange.Columns.Count < 2 Then
FuncWhoCol = "Not Two Columns!"
Exit Function
End If

'do the real work

myStr = ""
For Each myCell In inRange.Columns(2).Cells
If LCase(myCell.Value) = LCase(inMatch) Then
myStr = myStr & " " & myCell.Offset(0, -1).Value
End If
Next myCell

If myStr < "" Then
myStr = Mid(myStr, 2)
End If

FuncWhoCol = myStr

End Function

CNEWS wrote:

Hello

Excel 2003 query around VBA and how you access a Range

Consider two cols of data with people's favourite colour

A B
1) Fred Red
2) Sid Red
3) Bob Blue
4) Andy Reg
5) Steve Blue

What I want is to write the following
=funcWhoCol(A1:B5,"Blue")

The function will return a string containing the names of people whose
favourite colour matches the second parameter, in this case the strung
returned would be "Bob Steve"

I started to create a function and pass the range in as the first param
and the match string as the second but I can't find how to manipulate
the range in my function.

What I want is logically as shown below (although I have no idea about
how to do it so the code is nonsense)

function funcWhoCol is (inRange, inMatch)

for i_count = 1 to inRange.Cells.Count
if inRange(i_count) = inMatch then funcWhoCol = funcWhoCol +
inRange(i_count) + " "
next i_count

end function

Many thanks in advance
Craig


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default List of items in an array - VBA?

Dave

You are a genius

That is just the job

Many, many thanks

C

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
List and subtotal selected items, then print separate item list TitanG Excel Worksheet Functions 0 September 8th 08 09:07 PM
find each of the items in an array and save result in another array lif[_5_] Excel Programming 2 June 28th 06 01:54 AM
Data Validation: items in one list relate to items in another Paul D. Simon Excel Programming 1 August 4th 05 09:17 PM
named range, data validation: list non-selected items, and new added items KR Excel Discussion (Misc queries) 1 June 24th 05 05:21 AM
Items in disabled items list - unknown excel addins causing probs Rich Excel Programming 4 May 16th 05 10:31 PM


All times are GMT +1. The time now is 05:46 PM.

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"