Hi
I just begun using VBA
I wrote a function to extract a text item from a single row or single column of data entries. The text item chosesn is a numbered item and all non text is ignored. So if the list consisted of "AA","BB"," ","DD","EE" say then the input agruments (3,list) to the function would generate the result DD and similarly (2,list) would generate the result BB.
I wrote the function "nonzerotext" and the test harness subroutine "showtext" to display the output in a message box. This worked.
However, the function does not work alone in the spreadsheet. Any ideas.
See function and test harness below.
Private Function nonzerotext(listpos As Integer, List As Range) As String
Dim firstrow As Integer
Dim lastrow As Integer
Dim firstcolumn As Integer
Dim rowcounter As Integer
Dim numdetected As Integer
firstrow = List.Row
lastrow = List.Row + List.Count - 1
firstcolumn = List.Column
numdetected = 0
For rowcounter = firstrow To lastrow
If WorksheetFunction.IsText(List([rowcounter], [firstcolumn])) Then
numdetected = numdetected + 1
If numdetected = listpos Then
nonzerotext = List([rowcounter], [firstcolumn])
End If
End If
Next rowcounter
End Function
Sub showtext()
Dim textis As String
textis = nonzerotext(5, Range("A1:A10"))
MsgBox textis
End Sub
Bookmarks