Can anyone help with this module code. I simple want this funtion to work on both active sheets named within the code.... I think i have been working on this too long. Any suggestions will be greatly appreciated.
Function ConcatIf(ByVal compareRange As Range, ByVal xCriteria As Variant, Optional ByVal stringsRange As Range, Optional Delimiter As String, Optional NoDuplicates As Boolean) As String
'Performance fix - only run if target sheet is active
Dim s As String
s = ActiveSheet.Name
d = Acitvesheet.Name
If s <> "Target Grid" Then
Exit Function
If d <> "Target Grid Grades" Then
End If
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim i As Long, j As Long
With compareRange.Parent
Set compareRange = Application.Intersect(compareRange, Range(.UsedRange, .Range("a1")))
End With
If compareRange Is Nothing Then Exit Function
If stringsRange Is Nothing Then Set stringsRange = compareRange
Set stringsRange = compareRange.Offset(stringsRange.Row - compareRange.Row, stringsRange.Column - compareRange.Column)
Dim hasItems As Boolean
hasItems = False
For i = 1 To compareRange.Rows.Count
For j = 1 To compareRange.Columns.Count
If (Application.CountIf(compareRange.Cells(i, j), xCriteria) = 1) Then
If InStr(ConcatIf, Delimiter & CStr(stringsRange.Cells(i, j))) <> 0 Imp Not (NoDuplicates) Then
ConcatIf = ConcatIf & Delimiter & CStr(stringsRange.Cells(i, j))
hasItems = True
End If
End If
Next j
Next i
If hasItems Then
ConcatIf = Mid(ConcatIf, Len(Delimiter) + 1) + ChrW(10) + ChrW(10)
Else
ConcatIf = Mid(ConcatIf, Len(Delimiter) + 1)
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End Function
Function ConcatIf(ByVal compareRange As Range, ByVal xCriteria As Variant, Optional ByVal stringsRange As Range, Optional Delimiter As String, Optional NoDuplicates As Boolean) As String
'Performance fix - only run if target sheet is active
Dim s As String
s = ActiveSheet.Name
d = Acitvesheet.Name
If s <> "Target Grid" Then
Exit Function
If d <> "Target Grid Grades" Then
End If
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim i As Long, j As Long
With compareRange.Parent
Set compareRange = Application.Intersect(compareRange, Range(.UsedRange, .Range("a1")))
End With
If compareRange Is Nothing Then Exit Function
If stringsRange Is Nothing Then Set stringsRange = compareRange
Set stringsRange = compareRange.Offset(stringsRange.Row - compareRange.Row, stringsRange.Column - compareRange.Column)
Dim hasItems As Boolean
hasItems = False
For i = 1 To compareRange.Rows.Count
For j = 1 To compareRange.Columns.Count
If (Application.CountIf(compareRange.Cells(i, j), xCriteria) = 1) Then
If InStr(ConcatIf, Delimiter & CStr(stringsRange.Cells(i, j))) <> 0 Imp Not (NoDuplicates) Then
ConcatIf = ConcatIf & Delimiter & CStr(stringsRange.Cells(i, j))
hasItems = True
End If
End If
Next j
Next i
If hasItems Then
ConcatIf = Mid(ConcatIf, Len(Delimiter) + 1) + ChrW(10) + ChrW(10)
Else
ConcatIf = Mid(ConcatIf, Len(Delimiter) + 1)
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End Function