BradleyS
Active Member
- Joined
- Oct 28, 2006
- Messages
- 351
- Office Version
- 2010
- Platform
- Windows
I'm trying to pass two parameters (sr and colPos) from a sub to a function and get back the result (Names).
The function checks for a value in column H and if found gets the name in column B of the adjacent row
The Names variable will have a list of ; separate names
However, I keep getting a compile error "Expected array" in the sub with regards to "Names"
What am I doing wrong? How do I accomplish this?
The function checks for a value in column H and if found gets the name in column B of the adjacent row
The Names variable will have a list of ; separate names
However, I keep getting a compile error "Expected array" in the sub with regards to "Names"
What am I doing wrong? How do I accomplish this?
VBA Code:
Option Explicit
Sub Macro1()
Dim sr As String, colPos As Integer, Names As String, sn As String
sr = "H7:H"
colPos = 6
sn = Names(sr, colPos)
End Sub
Function Names(ByVal sr As String, ByVal colPos As Integer) As String
Dim output
Dim entry As Variant
Dim Lr As Long
Lr = ThisWorkbook.ActiveSheet.Range("B" & Rows.Count).End(xlUp).Row
On Error Resume Next 'if only 1 row
For Each entry In ThisWorkbook.ActiveSheet.Range(sr & Lr)
If Not IsEmpty(entry.Value) Then
output = output & entry.Offset(, -colPos).Value & ";"
End If
Next
Names = Left(output, Len(output) - 1)
End Function