VBA Message box - count instances in column to return result

mrsushi

Board Regular
Joined
Nov 18, 2006
Messages
180
Office Version
  1. 2010
Good afternoon,

Trying to incorporate other columns into the formula to count the number of instances which flag up the narrative "Check". So far the below formula counts up the value in column H, but I need a count for column I, L and M.

When the message box appears how can I for each line indicate the number of instances in each column?

Many thanks
M




VBA Code:
Sub CheckCounterMessageBox()
   
Dim instances As Long
   instances = WorksheetFunction.CountIf(Columns("H"), "CHECK")
   MsgBox "Found " & instances & " Price(s) to correct on DFL Ladder BID", vbInformation, "LS73 Reconcilations"
  
End Sub
 
Last edited by a moderator:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try:
VBA Code:
Sub CheckCounterMessageBox()
Dim instances As Long, Cols As Variant
Cols = Array(Columns("H"), Columns("I"), Columns("L"), Columns("M"))
For Each col In Cols
   instances = WorksheetFunction.CountIf(col, "CHECK")
   MsgBox "Found " & " in Column " & Left(col.Address(0, 0), 1) & ":  " & instances & " Price(s) to correct on DFL Ladder BID", vbInformation, "LS73 Reconcilations"
Next col
  
End Sub
 
Last edited:
Upvote 0
Hi,
one way maybe

VBA Code:
Sub CheckCounterMessageBox()
    Dim instances As Long
    Dim rng As Range, col As Range
    
    Set rng = Range("H:H,I:I,L:L,M:M")
    For Each col In rng.Columns
        instances = instances + WorksheetFunction.CountIf(col, "CHECK")
    Next
    
    MsgBox "Found " & instances & " Price(s) to correct on DFL Ladder BID", vbInformation, "LS73 Reconcilations"

End Sub

but sure someone will have a non-looping suggestion

Dave
 
Upvote 0
Many thanks
Try:
VBA Code:
Sub CheckCounterMessageBox()
Dim instances As Long, Cols As Variant
Cols = Array(Columns("H"), Columns("I"), Columns("L"), Columns("M"))
For Each col In Cols
   instances = WorksheetFunction.CountIf(col, "CHECK")
   MsgBox "Found " & " in Column " & Left(col.Address(0, 0), 1) & ":  " & instances & " Price(s) to correct on DFL Ladder BID", vbInformation, "LS73 Reconcilations"
Next col
 
End Sub
many thanks for the formula. This sums up the number of checks which is good. However, is it possible to group the count as per column? I've attached image so you can see how many checks per column.
 

Attachments

  • CHECK COLUMNS.JPG
    CHECK COLUMNS.JPG
    62.6 KB · Views: 18
Upvote 0
Hi,
one way maybe

VBA Code:
Sub CheckCounterMessageBox()
    Dim instances As Long
    Dim rng As Range, col As Range
   
    Set rng = Range("H:H,I:I,L:L,M:M")
    For Each col In rng.Columns
        instances = instances + WorksheetFunction.CountIf(col, "CHECK")
    Next
   
    MsgBox "Found " & instances & " Price(s) to correct on DFL Ladder BID", vbInformation, "LS73 Reconcilations"

End Sub

but sure someone will have a non-looping suggestion

Dave
many thanks for the formula. This sums up the number of checks which is good. However, is it possible to group the count as per column? I've attached image so you can see how many checks per column.
 
Upvote 0
Many thanks

many thanks for the formula. This sums up the number of checks which is good. However, is it possible to group the count as per column? I've attached image so you can see how many checks per column.
Look again at my post which I edited after you read it. It now gives you the count by column in separate message boxes.
 
Upvote 0
many thanks for the formula. This sums up the number of checks which is good. However, is it possible to group the count as per column? I've attached image so you can see how many checks per column.

maybe

VBA Code:
Sub CheckCounterMessageBox()
    Dim instances As Long
    Dim rng As Range, col As Range
    Dim str As String
    
    Set rng = Range("H:H,I:I,L:L,M:M")
    For Each col In rng.Columns
        instances = WorksheetFunction.CountIf(col, "CHECK")
        str = str & Left(col.Address(0, 0), 1) & " - " & instances & Chr(10)
        
    Next
    
    MsgBox "Found Price(s) to correct on DFL Ladder BID" & Chr(10) & str, vbInformation, "LS73 Reconcilations"

End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
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