Hi,
Three of my subs in module have the exact same part of the script that does the same thing and I wish I could put it in function but I don't know how... I had trouble because the two variables (strLine and clrLine) rely on each other.
Sub chkTP()
'<---!here--------------------------------------------->
Dim strLine As String
Dim fndLine As Range
Set fndLine = Range("J2:J5").Find("+")
Dim clrLine As Integer
Dim modSuit(1 To 3) As Range
Set modSuit(1) = Range("AH3")
Set modSuit(2) = Range("AH4")
Set modSuit(3) = Range("AH4")
'<---!to here------------------------------------------>
Dim selSuit(1 To 3) As Range
Set selSuit(1) = Cells(ActiveCell.Row, ActiveCell.Column + 6)
Set selSuit(2) = Cells(ActiveCell.Row + 1, ActiveCell.Column + 6)
Set selSuit(3) = Cells(ActiveCell.Row + 2, ActiveCell.Column + 6)
'<---!here--------------------------------------------->
If fndLine Is Nothing Then
strLine = "x"
Else
strLine = fndLine.Offset(0, 1).Value
End If
Select Case strLine
Case "2b.4b", "3b.5b"
clrLine = 35
Case "2b.c3b", "3b.c4b"
clrLine = 37
Case "2b.fd", "3b.fd"
clrLine = 24
Case "c2b"
clrLine = 36
Case "x"
clrLine = 0
End Select
'<---!to here------------------------------------------>
For i = 1 To 3
If modSuit(i).Value = "+" Then
selSuit(i).Value = strLine
selSuit(i).Font.ColorIndex = clrLine
selSuit(i).Interior.ColorIndex = clrLine
End If
Next i
End Sub
I've highlighted the two portions I would like to "convert" to function. Could you show me how?
Bookmarks