AlexanderBB
Well-known Member
- Joined
- Jul 1, 2009
- Messages
- 2,040
- Office Version
- 2019
- 2010
- Platform
- Windows
Goal: To obtain a vblf delimited string containing all the values in FoundCol.
The Line remmed out went to error with Nothing as invalid use of object. Odd?
.UsedRange.Columns("G").Value incuded the highest row in the sheet, not just rows in FoundCol so lrow number was needed. Should it be?
And is the y loop required or there a better way ?
VBA Code:
Private Function Obtain(r As Range) As String
Dim Data()
Dim y As Long
Dim FoundCol As String
Dim lRow As Long
If Left(r(, 3), 2) = "LP" Then 'Match Confirmed
With Worksheets("Tracks").Range("A:Z")
' If .Find(What:=r(, 3), lookIn:=xlValues) Is Not Nothing Then
FoundCol = ColLetter(.Find(What:=r(, 3), lookIn:=xlValues).Column)
lRow = .Range(FoundCol & "200").End(xlUp).Row 'No rows > 200
Data = Worksheets("Tracks").UsedRange.Columns(FoundCol).Value
For y = 1 To lRow
Obtain = Obtain & Data(y, 1) & vbLf
Next
End With
End If
End Function
Function colLetter(intNumber) As String
If Val(intNumber) = 0 Then
colLetter = ""
Else
colLetter = Left(Cells(1, Val(intNumber)).address(0, 0), 2 + (Val(intNumber) <= 26))
End If
End Function
.UsedRange.Columns("G").Value incuded the highest row in the sheet, not just rows in FoundCol so lrow number was needed. Should it be?
And is the y loop required or there a better way ?