I have a macro that needs to be changed to a function.
The macro will have to change to select the cells (relatively) of C2:C44 from cell C45(the cell that will call the function). Here is my macro:
Sub NewHires()
Dim totNew As Long
Dim numN As Long
Dim cmt As Comment
Dim sStrN As String
Dim ilocN As Long
Dim myKeyWordsN As Variant
Dim iCtrN As Long
Dim rng As Range
Set rng = Selection
myKeyWordsN = Array("new hire")
totNew = 0
For Each cmt In ActiveSheet.Comments
If Intersect(cmt.Parent, rng) Is Nothing Then
Else
For iCtrN = LBound(myKeyWordsN) To UBound(myKeyWordsN)
sStrN = cmt.Text
Do
ilocN = InStr(1, sStrN, myKeyWordsN(iCtrN), vbTextCompare)
If ilocN > 0 Then
If IsNumeric(Mid(sStrN, ilocN - 2, 2)) Then
numN = CLng(Mid(sStrN, ilocN - 2, 2))
totNew = numN + totNew
Else
MsgBox "Error on: " & cmt.Parent.Address(0, 0)
End If
Else
Exit Do
End If
sStrN = Mid(sStrN, ilocN + Len(myKeyWordsN(iCtrN)))
Loop
Next iCtrN
End If
Next cmt
ActiveCell.Offset(43, 0).Range("A1).Select
ActiveCell.FormulaR1C1 = totNew
The macro orignally checked the comments in a selected range and place a numeric value into cell C45 based on the criteria. If the comment in a cell had "# New Hires", it would take the # and add it to the next # in the next cell that had a comment with "new hire" in it. I want this to become a function so that it is MORE automatic than before.
Thanks in advance!!!