Created
October 5, 2016 03:10
-
-
Save webdawe/0d4337795476c42212b5baa2026ee804 to your computer and use it in GitHub Desktop.
Excel Vba Script to Get Values from a Range for Comma Seperated Values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Function ListValues(CSVList As String, rg As Range, NumberColumn As Long) | |
Dim findlist() As String | |
Dim listData As Variant | |
'Dim rg As Range | |
Dim colVal As Integer | |
'Set rg = Sheet2.Range("A2:B243") | |
Dim NumEntries As Long | |
Dim i As Long | |
findlist = Split(CSVList, ",") | |
NumEntries = UBound(findlist) - LBound(findlist) + 1 | |
listData = "" | |
On Error Resume Next | |
For i = LBound(findlist) To UBound(findlist) | |
colVal = findlist(i) | |
If listData <> "" Then | |
listData = listData & ", " | |
End If | |
listData = listData & Application.WorksheetFunction.VLookup(colVal, rg, NumberColumn, False) | |
If Err.Number <> 0 Then | |
ListValues = Err.Number | |
Exit Function | |
End If | |
Next i | |
ListValues = listData | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment