View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jeff Jeff is offline
external usenet poster
 
Posts: 921
Default Passing arguments to a module in a Cell

I pass a string from a cell to a module.

Assumming A1 contains the string var 'Procurement'
I execute a Function or Sub based on this
string in cell A1

=PopulateData("Procurement")

However this does not give me the
Range value 'Range("D" & LRow).Value'????

If I change the program to a Subroutine is works

Function PopulateData(var As Variant) As String
Dim ServiceGroup As Variant
Dim SName As String
Dim SDescription As String
Dim LRow As Long
Dim LFound As Boolean

Sheets("Vendor Management").Select
'ServiceGroup = Range("A1").Value
ServiceGroup = var

LFound = False
LRow = 2
Sheets("Input data").Select
GetRng LRow
Do While LFound = False
If Range("D" & LRow).Value = ServiceGroup Then
LFound = True
SName = Range("A" & LRow).Value
SDescription = Range("G" & LRow).Value

Sheets("Service List").Select
Range("B8").Value = SName
Range("B9").Value = SDescription

ElseIf IsEmpty(Range("A" & LRow).Value) = True Then
'MsgBox ("No match was found.")
'Exit Sub
End If
LRow = LRow + 1
Loop
End Function

--
Jeff :-)