Advertisement
iAmGhost

Untitled

Oct 14th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Function GetReceipt(NamesRange As Range, ValuesRange As Range) As String
  2.     Dim I As Integer
  3.     Dim Value As Integer
  4.     Dim Name As String
  5.     Dim FoundCount As Integer
  6.     Dim LastName As String
  7.    
  8.     FoundCount = 0
  9.    
  10.     For I = 1 To ValuesRange.Columns.Count
  11.         Value = ValuesRange.Cells(1, I).Value
  12.         Name = NamesRange.Cells(1, I)
  13.        
  14.         If Value > 0 Then
  15.             ResultString = ResultString & Name & "-" & Value & ","
  16.             LastName = Name
  17.             FoundCount = FoundCount + 1
  18.         End If
  19.     Next I
  20.    
  21.     If FoundCount = 1 Then
  22.         ResultString = LastName
  23.     ElseIf FoundCount = 0 Then
  24.         ResultString = ""
  25.     Else
  26.         ResultString = Left(ResultString, Len(ResultString) - 1)
  27.     End If
  28.    
  29.     GetReceipt = ResultString
  30. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement