VBA Auto-Insert comments based on Countifs?

taostep1

Board Regular
Joined
May 18, 2016
Messages
65
Good afternoon Excel Wizards,

Another fun Excel challenge here. Please consider the following:


  • I have a sheet named "Confirmed Movement" that lists Rank numbers in column H, Group names in column I, Month names in column Q, Transaction types in column O, Transaction dates in column P, and Employee names in column C.
  • On another sheet, I have a Summary table populated with countifs (formulas) in multiple rows that returns the actual count based on the Rank number, Group name, Month name, and Transaction Type criteria.
  • Now, I want to install VBA that will identify the number in each Countifs cell of the Summary and add a comment containing all of the Employee names and Transaction dates that apply.

The reason for this is that it takes me hours to populate manually especially if there are over 2000 comments I have to input every other week.

This would be an absolute time saver if there is any solution!

Thanks,
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
This is not exactly trivial, but doable. A few details first, though.

1. What is the last column on this worksheet? This is to determine the first column where it is "safe" to add more columns (for filtering), which are temporary and will be deleted.
2. Is your data range contiguous? Meaning, if you put your active cell somewhere in the middle of the data, and press Ctrl+Shift+8, will the entire data set get selected?
3. Can you show an example of a COUNTIF function? If some of them are significantly different from others, please post a few examples.
 
Last edited:
Upvote 0
1. Last column is BZ
2. It is not contiguous given that there are small tables broken out throughout the entire Summary sheet.
3. Examples below: Please note that C7 represents the month, A126 represents the rank, and A124 represents the group.

=COUNTIFS('FY19 Confirmed Movement'!$O$1:$O$8078,"Hire",'FY19 Confirmed Movement'!$I$1:$I$8078,$A$124,'FY19 Confirmed Movement'!$H$1:$H$8078,$A126,'FY19 Confirmed Movement'!$Q$1:$Q$8078,$C$7)

=-COUNTIFS('FY19 Confirmed Movement'!$O$1:$O$8078,"Separation",'FY19 Confirmed Movement'!$I$1:$I$8078,$A$124,'FY19 Confirmed Movement'!$H$1:$H$8078,$A126,'FY19 Confirmed Movement'!$Q$1:$Q$8078,$C$7)

=COUNTIFS('FY19 Confirmed Movement'!$O$1:$O$8078,"Transfer In",'FY19 Confirmed Movement'!$I$1:$I$8078,$A$124,'FY19 Confirmed Movement'!$H$1:$H$8078,$A126,'FY19 Confirmed Movement'!$Q$1:$Q$8078,$C$7)

=-COUNTIFS('FY19 Confirmed Movement'!$O$1:$O$8078,"Transfer Out",'FY19 Confirmed Movement'!$I$1:$I$8078,$A$124,'FY19 Confirmed Movement'!$H$1:$H$8078,$A126,'FY19 Confirmed Movement'!$Q$1:$Q$8078,$C$7)
 
Last edited:
Upvote 0
What are the specific column names on 'FY19 Confirmed Movement' sheet, for "Rank numbers in column H, Group names in column I, Month names in column Q, Transaction types in column O, Transaction dates in column P, and Employee names in column C."

Because you say them in the plural for 'Confirmed Movement' sheet, but then say them in the singular for 'Summary' sheet: "I have a Summary table populated with countifs (formulas) in multiple rows that returns the actual count based on the Rank number, Group name, Month name, and Transaction Type criteria.

Are they literally "Rank numbers" or "Rank number"? Plural or singular?
 
Last edited:
Upvote 0
Correct. they are plural given the nature of the countifs searching through multiple rank names, Group names, Month names, and Transaction types.
 
Upvote 0
OK, got it. Working on it, will have something for you to try in a few hours.
 
Upvote 0
OK, proof of concept (a.k.a. "here goes nothing")...

Two caveats:
1. I have only tried this on a limited set of data. So before you get your hopes up, please keep in mind that there could still be errors and bugs.
2. I turned off the error handler for the purposes of debugging. This means that if an error occurs, it will give you an option to End or Debug. Please click Debug, and paste the offending line in your reply, so we can troubleshoot.

With that out of the way - can you please try this code on a copy of your workbook? Paste it in a standard module, select one or more COUNTIFS cells on your Summary sheet, and run the InsertComments macro. Post back with the result. In the meantime, I will tweak, and put in interlinear comments so you can digest the code if you want (and for posterity).

Code:
Private Const msLAST_CELL As String = "BZ" 'only the column name
Private Const msNAME_SEPARATOR As String = vbCrLf
Private Const msFORMULA_SEPARATOR As String = ","

Private Const msNAMES_COLUMN As String = "C:C"

Private Const msDATA_SHEET As String = "FY19 Confirmed Movement"
Private Const msSUMMARY_SHEET As String = "Summary"

Private Const msNOTICE_TEXT_LEFT As String = vbCrLf & "...and another "
Private Const msNOTICE_TEXT_RIGHT As String = " item(s)."

Private Const miMAX_COMMENT_LENGTH As Long = 32767


Private msSource As String


Public Sub InsertComment()
  Dim rngSel As Excel.Range
  Dim rng As Excel.Range
  
  Dim vCriteria As Variant
  
  Dim i As Integer
  
  Dim sFormula As String
  Dim sResult As String
  
  Dim calcs As Excel.XlCalculation
  
  msSource = "InsertComment entry point procedure"
  
'  On Error GoTo cleanup
  
  With Application
    calcs = .Calculation
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
  End With
  
  If StrComp(LCase$(TypeName(Selection)), "range") <> 0 Then
    Call MsgBox("Please select some cells first!", vbOKOnly + vbInformation)
    GoTo cleanup
  End If
  
  Set rngSel = Application.Selection
  
  For Each rng In rngSel.Cells
    If rng.HasFormula Then
      sFormula = rng.Formula
      
      If InStr(1, UCase$(sFormula), "COUNTIFS") > 0 Then
        rng.Calculate
        
        If Abs(rng.Value) > 0 Then
          vCriteria = vParseFormula(sFormula)
          msSource = "InsertComment entry point procedure"
          sResult = sGetNames(vCriteria)
          msSource = "InsertComment entry point procedure"
        Else
          sResult = "The criteria returns zero results."
        End If
        
        ' add the comment
        On Error Resume Next
          rng.Comment.Delete
        On Error GoTo cleanup
          
        rng.AddComment sResult
      Else
        Debug.Print "'" & rng.Parent.Name & "'!" & rng.Address & " does not contain a COUNTIFS."
      End If
      
    End If
  Next rng
  
cleanup:
  With Application
    .Calculation = calcs
    .ScreenUpdating = True
  End With
    
  If Err.Number <> 0 Then
    Call MsgBox("An error occurred :(" & _
          vbCrLf & vbCrLf & Err.Number & ": " & Err.Description & _
          vbCrLf & vbCrLf & "Source: " & msSource, vbExclamation + vbOKOnly, "Oops...")
  End If
  
End Sub



Private Function iGetNumLen(iNum As Long) As Integer
  msSource = "iGetNumLen private function"
  iGetNumLen = Application.WorksheetFunction.RoundUp(Log(iNum + 1) / Log(10), 0)
End Function


Private Function vParseFormula(sFormula As String) As Variant
  Dim iLeftParen As Integer
  Dim iRightParen As Integer
  Dim sSubstring As String
  
  Dim v As Variant
  
  msSource = "vParseFormula private function"
  
  
  iLeftParen = InStr(1, sFormula, "(")
  iRightParen = InStr(1, sFormula, ")")
  
  sSubstring = Mid$(Trim(sFormula), iLeftParen + 1, iRightParen - iLeftParen - 1)
  
  vParseFormula = Split(sSubstring, msFORMULA_SEPARATOR)
End Function



Private Function sGetNames(vCriteria As Variant) As String
  Dim rngResult As Excel.Range
  
  Dim rngData As Excel.Range
  Dim rngCriteria As Excel.Range
  Dim rngOutput As Excel.Range
  
  Dim sValue As String
  Dim rngValue1 As Excel.Range
  Dim rngValue2 As Excel.Range
  
  Dim rng As Excel.Range
  
  Dim wshSummary As Excel.Worksheet
  Dim wshData As Excel.Worksheet
  
  Dim iMaxLen As Long
  Dim iNumCriteria As Long

  Dim i As Long
  Dim j As Long
  
  Dim bOverflow As Boolean
  
  msSource = "sGetNames private function"
  
  Set wshSummary = ActiveWorkbook.Worksheets(msSUMMARY_SHEET)
  Set wshData = ActiveWorkbook.Worksheets(msDATA_SHEET)
  
  ReDim Preserve vCriteria(1 To UBound(vCriteria) + 1)
  
  iNumCriteria = (UBound(vCriteria) - LBound(vCriteria) + 1) / 2
  
  ReDim vHeaders(1 To iNumCriteria, 1 To 2)

  ' set up the criteria array
  For i = 1 To UBound(vCriteria) Step 2
    j = i + 1
    
    If InStr(1, vCriteria(i), "!") > 0 Then
      Set rngValue1 = Range(vCriteria(i)).Cells(1)
    Else
      Set rngValue1 = wshData.Range(vCriteria(i)).Cells(1)
    End If
    vHeaders(j / 2, 1) = rngValue1.Value
    
    If InStr(1, vCriteria(j), """") > 0 Then
      vHeaders(j / 2, 2) = "=" & Mid(vCriteria(j), 1, Len(vCriteria(j)))
    Else
      If InStr(1, vCriteria(j), "!") Then
        Set rngValue2 = Range(vCriteria(j))
      Else
        Set rngValue2 = wshSummary.Range(vCriteria(j))
      End If
      vHeaders(j / 2, 2) = rngValue2.Value
    End If
  Next i
  
  Set rngData = Intersect(wshData.Range("A:" & msLAST_CELL).EntireColumn, wshData.UsedRange)
  
  Set rngCriteria = wshData.Range(msLAST_CELL & "1").Offset(0, 2).Resize(UBound(vHeaders, 2) - LBound(vHeaders, 2) + 1, UBound(vHeaders, 1) - LBound(vHeaders, 1) + 1)
  rngCriteria.Value = Application.WorksheetFunction.Transpose(vHeaders)
  
  Set rngOutput = wshData.Range(msLAST_CELL & "1").Offset(0, 2 + rngCriteria.Columns.Count + 1)
'  rngOutput.Value = Intersect(rngValue1.EntireRow, wshData.Range(msNAMES_COLUMN).EntireColumn)
  
  rngOutput.Value = wshData.Range(msNAMES_COLUMN).Cells(1).Value
  
  rngData.AdvancedFilter xlFilterCopy, rngCriteria, rngOutput, unique:=True
  
  iMaxLen = miMAX_COMMENT_LENGTH - Len(msNOTICE_TEXT_LEFT) - Len(msNOTICE_TEXT_RIGHT) - iGetNumLen(rngData.Rows.Count)
  msSource = "sGetNames private function"
  
  Set rngResult = Range(rngOutput, rngOutput.End(xlDown))
  Set rngResult = rngResult.Offset(1, 0).Resize(rowsize:=rngResult.Rows.Count - 1)
  
  j = 0
  sGetNames = ""
  
  For Each rng In rngResult.Cells
    sValue = rng.Value
    If Len(sValue) + Len(sGetNames) + iMaxLen > miMAX_COMMENT_LENGTH Then
      j = j + 1
    Else
      sGetNames = sGetNames & sValue & msNAME_SEPARATOR
    End If
  Next rng
  
  If j > 0 Then
    sGetNames = sGetNames & msNOTICE_TEXT_LEFT & j & msNOTICE_TEXT_RIGHT
  End If
  
End Function
 
Upvote 0
Wow, I can’t fathom how much time you put into this! Once I get home, I will be trying this out in the workbook module asap!

Thank you so much in advance for putting your hard work into this! :)
 
Upvote 0
Alright, so the error message I receive is per the following below. Any thoughts?

Set rngResult = rngResult.Offset(1, 0).Resize(rowsize:=rngResult.Rows.Count - 1)
 
Upvote 0
OK, now comes the interesting part - troubleshooting and debugging.

First of all, I have made some adjustments to the code since we last spoke, and also put in some interlinear comments to explain what each part does. This may very well solve the problem (the adjustments, not the comments).

The way this macro works is it uses Advanced Filter functionality to replicate the results of COUNTIFS, except instead of counting, it actually filters out the Employee names column. The line where you get the error message is trying to capture the names that are extracted by the filter operation, to be inserted into the comment. So, we need to establish two things:
1. What is the exact error you are receiving? E.g. something like "Subscript out of range"
2. What is the output from the filter operation at that time? Go to your data sheet (FY19 Confirmed Movement), and look beyond column Z.

There will be four (or however many) columns that are the filter criteria (e.g. Transaction types, Group names, Rank numbers, Month names), and then a little more to the right, the filter output (e.g. Employee names). Check two things here:
1. Headers are correct and match exactly your columns C, H, I, O, Q.
2. What are the values below the headers?

Post back with what you find. But, also, try this updated code and see if the error still occurs. I know when I was testing, I got it at one point, but I don't remember exactly the circumstances.

Rich (BB code):
'only the column name of the last cell in the report
Private Const msLAST_CELL As String = "BZ"
' you can change this to vbTab or " " if you do not want a new line after each name
Private Const msNAME_SEPARATOR As String = vbCrLf
' do not change this unless you are adapting to a foreign version of Excel where formula parameters are separated by something other than a comma
Private Const msFORMULA_SEPARATOR As String = "," 
' this is the column address where the Name is located on the data sheet; adjust if necessary
Private Const msNAMES_COLUMN As String = "C:C" 
' name of the data sheet; update for each new year
Private Const msDATA_SHEET As String = "FY19 Confirmed Movement" 
' name of the summary sheet, where the COUNTIFS functions are located
Private Const msSUMMARY_SHEET As String = "Summary" 
' the comment will say this if COUNTIFS returns 0
Private Const msZERO_RESULTS_TEXT As String = "The criteria returns zero results." 
' left side of the notice if comment length is exceeded
Private Const msNOTICE_TEXT_LEFT As String = vbCrLf & "...and another " 
'right side of the notice if comment length is exceeded; the number of skipped names is inserted between
Private Const msNOTICE_TEXT_RIGHT As String = " item(s)." 
'maximum length of a comment, in characters; do not exceed 32,000; reduce if you want comments to be shorter
Private Const miMAX_COMMENT_LENGTH As Long = 32000 
' this string will store the procedure currently used, and will be reported if an error occurs; this helps for troubleshooting / debugging
Private msSource As String



Public Sub InsertComment()
  Dim rngSel As Excel.Range
  Dim rng As Excel.Range
  
  Dim vCriteria As Variant
  
  Dim i As Integer
  
  Dim sFormula As String
  Dim sResult As String
  
  Dim calcs As Excel.XlCalculation
  
  msSource = "InsertComment entry point procedure"
  
'  On Error GoTo cleanup
' turn off automatic calculations for faster execution
  With Application
    calcs = .Calculation
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
  End With
  
  ' make sure the selection is a range
  If StrComp(LCase$(TypeName(Selection)), "range") <> 0 Then
    Call MsgBox("Please select some cells first!", vbOKOnly + vbInformation)
    GoTo cleanup
  End If
  
  Set rngSel = Application.Selection
  
  ' loop through the selected cells
  For Each rng In rngSel.Cells
    ' only process cells that have a formula
    If rng.HasFormula Then
      sFormula = rng.Formula
      
      ' only process formula cells that have a COUNTIFS function
      If InStr(1, UCase$(sFormula), "COUNTIFS") > 0 Then
        ' recalculate the current cell
        rng.Calculate
        
        ' make sure the cell is non-zero value
        ' if the COUNTIFS returns zero, we skip to the next cell
        If Abs(rng.Value) > 0 Then
          vCriteria = vParseFormula(sFormula)
          msSource = "InsertComment entry point procedure"
          sResult = sGetNames(vCriteria)
          msSource = "InsertComment entry point procedure"
        Else
          sResult = msZERO_RESULTS_TEXT
        End If
        
        ' add the comment
        ' delete any previous comment
        On Error Resume Next
          rng.Comment.Delete
        On Error GoTo cleanup
          
        rng.AddComment sResult
        
      Else
        Debug.Print "'" & rng.Parent.Name & "'!" & rng.Address & " does not contain a COUNTIFS."
      End If
      
    End If
  Next rng
  
cleanup:
  ' restore settings
  With Application
    .Calculation = calcs
    .ScreenUpdating = True
  End With
  
  ' if there is an error message, report this information
  If Err.Number <> 0 Then
    Call MsgBox("An error occurred :(" & _
          vbCrLf & vbCrLf & Err.Number & ": " & Err.Description & _
          vbCrLf & vbCrLf & "Source: " & msSource, vbExclamation + vbOKOnly, "Oops...")
  End If
  
End Sub

' This function returns the digit length of an integer
' 1-9 = 1
' 10-99 = 2
' 100-999 = 3
' etc
Private Function iGetNumLen(iNum As Long) As Integer
  msSource = "iGetNumLen private function"
  iGetNumLen = Application.WorksheetFunction.RoundUp(Log(iNum + 1) / Log(10), 0)
End Function

' This function returns a one-dimensional array containing the parameters of a COUNTIFS function
' Only the first COUNTIFS function will be considered
Private Function vParseFormula(sFormula As String) As Variant
  Dim iLeftParen As Integer
  Dim iRightParen As Integer
  Dim sSubstring As String
  
  Dim v As Variant
  
  msSource = "vParseFormula private function"
  
  ' find the opening and closing parentheses
  iLeftParen = InStr(1, sFormula, "COUNTIFS")
  iLeftParen = InStr(iLeftParen, sFormula, "(")
  iRightParen = InStr(1, sFormula, ")")
  
  ' extract the parameters in-between the parentheses
  sSubstring = Mid$(Trim(sFormula), iLeftParen + 1, iRightParen - iLeftParen - 1)
  
  ' split the string by delimeter, isolating each of the parameters
  vParseFormula = Split(sSubstring, msFORMULA_SEPARATOR)
End Function

' This function performs an Advanced Filter operation, and returns a delimited list of values
'     that match the criteria of a COUNTIFS function.
' The input is a one-dimensional variant array of the parameters of a COUNTIFS function
Private Function sGetNames(vCriteria As Variant) As String
  Dim rngResult As Excel.Range
  
  Dim rngData As Excel.Range
  Dim rngCriteria As Excel.Range
  Dim rngOutput As Excel.Range
  
  Dim sValue As String
  Dim rngValue1 As Excel.Range
  Dim rngValue2 As Excel.Range
  
  Dim rng As Excel.Range
  
  Dim wshSummary As Excel.Worksheet
  Dim wshData As Excel.Worksheet
  
  Dim iMaxLen As Long
  Dim iLenNotice As Long
  
  Dim iNumCriteria As Long
  Dim iShift As Long
  Dim i As Long
  Dim j As Long
  
  Dim s As String
  
  msSource = "sGetNames private function"
  
  ' identify the relevant sheets
  Set wshSummary = ActiveWorkbook.Worksheets(msSUMMARY_SHEET)
  Set wshData = ActiveWorkbook.Worksheets(msDATA_SHEET)
  
  ' shift the array so that it is 1-to-N dimensionality
  ' this avoids the computational issues related to zero-based arrays, or a non-standard dimensionality
  iShift = 1 - LBound(vCriteria)
  ReDim Preserve vCriteria(LBound(vCriteria) + iShift To UBound(vCriteria) + iShift)
  
  ' this is OK because the array is now a 1-based index
  iNumCriteria = UBound(vCriteria) / 2
  
  ' create the two-dimensional array to hold the Advanced Filter criteria
  ReDim vHeaders(1 To iNumCriteria, 1 To 2)
  ' set up the criteria array
  ' each odd-numbered element is COUNTIFS criteria range
  ' each even-numbered element is COUNTIFS criteria value
  For i = 1 To UBound(vCriteria) Step 2
    ' i is the counter for criteria range
    ' j is the counter for criteria value
    j = i + 1
    
    ' look at the odd-numbered element
    ' if the criteria contains a sheet name (determined by presence of !), use the entire criteria
    ' if the criteria does not contain a cell range (determined by absence of :), assume it is a named range and use the entire criteria
    ' absent the above conditions, assume the criteria is a range on the Data sheet
    If InStr(1, vCriteria(i), "!") > 0 Or InStr(1, vCriteria(i), ":") < 1 Then
      Set rngValue1 = Range(Trim(vCriteria(i))).Cells(1)
    Else
      Set rngValue1 = wshData.Range(Trim(vCriteria(i))).Cells(1)
    End If
    
    ' extract the value for the filter field
    vHeaders(j / 2, 1) = rngValue1.Value
    
    ' look at the adjacent even-numbered element
    ' if the criteria contains a double quote, it is a constant
    ' if it begins with characters (=, <, >) then it is already a complete string
    ' otherwise, insert =
    If InStr(1, vCriteria(j), """") > 0 Then
      s = Left(Trim(vCriteria(j)), 1)
      If s = "=" Or s = "<" Or s = ">" Then
        vHeaders(j / 2, 2) = vCriteria(j)
      Else
        vHeaders(j / 2, 2) = "=" & vCriteria(j)
      End If
    Else
    ' if the criteria does not contain a double-quote, then it is a cell address
    ' if it is specific to a sheet (determined by presence of !), use that reference
    ' otherwise, assume that it is a range on the Summary sheet
      If InStr(1, vCriteria(j), "!") Then
        Set rngValue2 = Range(Trim(vCriteria(j)))
      Else
        Set rngValue2 = wshSummary.Range(Trim(vCriteria(j)))
      End If
      ' extract the value for the criteria value
      vHeaders(j / 2, 2) = rngValue2.Value
    End If
  Next i
  
  ' find the data range to filter
  ' assume UsedRange of the data sheet is the entirety of rows needed to filter
  Set rngData = Intersect(wshData.Range("A:" & msLAST_CELL).EntireColumn, wshData.UsedRange)
  
  ' delete all fitering data
  Set rng = rngData.Columns(rngData.Columns.Count).EntireColumn.Offset(0, 1).Resize(columnsize:=rngData.Parent.Cells.Columns.Count - rngData.Columns.Count)
  rng.EntireColumn.Delete
  ' set up the Criteria range for Advanced Filter, and populate the criteria array
  Set rngCriteria = wshData.Range(msLAST_CELL & "1").Offset(0, 2).Resize(UBound(vHeaders, 2) - LBound(vHeaders, 2) + 1, UBound(vHeaders, 1) - LBound(vHeaders, 1) + 1)
  rngCriteria.Value = Application.WorksheetFunction.Transpose(vHeaders)
  
  ' set up the output range for Advanced Filter
  Set rngOutput = wshData.Range(msLAST_CELL & "1").Offset(0, 2 + rngCriteria.Columns.Count + 1)
  rngOutput.Value = wshData.Range(msNAMES_COLUMN).Cells(1).Value
  
  ' perform the advanced filter operation
  rngData.AdvancedFilter xlFilterCopy, rngCriteria, rngOutput, unique:=True
  
  ' determine the maximum comment length
  ' if the length of the comment reaches above this limit, an overflow text is appended at the end of the comment
  ' the overflow comment indicates how many additional records are not displayed
  iLenNotice = Len(msNOTICE_TEXT_LEFT) + Len(msNOTICE_TEXT_RIGHT) + iGetNumLen(rngData.Rows.Count)
  iMaxLen = miMAX_COMMENT_LENGTH - iLenNotice
  
  msSource = "sGetNames private function"
  
  ' get the output results of Advanced Filter
  Set rngResult = Range(rngOutput, rngOutput.End(xlDown))
  Set rngResult = rngResult.Offset(1, 0).Resize(rowsize:=rngResult.Rows.Count - 1)
  
  ' create the output string with delimited names
  j = 0
  sGetNames = ""
  
  ' look through each cell in the filter result
  ' if the comment is not too long, add it to the list
  ' if the name exceeds max comment list, add it to overflow count
  For Each rng In rngResult.Cells
    sValue = rng.Value
    If Len(sValue) + Len(sGetNames) > miMAX_COMMENT_LENGTH Then
      j = j + 1
    Else
      sGetNames = sGetNames & sValue & msNAME_SEPARATOR
    End If
  Next rng
  ' delete the last separator  
  If Len(sGetNames) > 0 Then
    sGetNames = Left$(sGetNames, Len(sGetNames) - 1)
  End If
  
  ' if there is any overflow names that were excluded, append the notice with the total count of excluded positions
  If j > 0 Then
    sGetNames = sGetNames & msNOTICE_TEXT_LEFT & j & msNOTICE_TEXT_RIGHT
  End If
  
  ' remove the temporary filter criteria and result fields
  rngCriteria.Resize(columnsize:=rngCriteria.Columns.Count + 2).EntireColumn.Delete
  
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top