Whenever I run the 'CleanTrim_Selected_Cells' macro (see above), the code for no apparent reason jumps into the Function section of the below macro (EnterSumFormula_MyResults). Why??? The below macro also works on the 'MyResults' Worksheet (strSheet = ActiveWorkbook.Worksheets("MyResults").Name)
If I run the 'CleanTrim_SelectedCells' macro in another workbook, everything runs fine and smoothly.
Help is much appreciated. Thank you very much in advance.
Regards, Andreas
Sub EnterSumFormula_MyResults() Dim rng As Range Dim LastRow As Long Dim strSheet As Variant Dim strFormula As Variant strSheet = ActiveWorkbook.Worksheets("MyResults").Name LastRow = Sheets(strSheet).Range("B" & Cells.Rows.Count).End(xlUp).Row strFormula = "=CountByColor('" & strSheet & "'!$B$4" & ", '" & strSheet & "'!$B$4:$B$" & LastRow & ")" ActiveWorkbook.Sheets("2_Auswertung").Range("B5").Formula = strFormulaEnd SubFunction CountByColor(CellColor As Range, CountRange As Range) Application.Volatile Dim ICol As Integer Dim TCell As Range ICol = CellColor.Interior.ColorIndex For Each TCell In CountRange If ICol = TCell.Interior.ColorIndex Then CountByColor = CountByColor + 1 End If Next TCellEnd Function