Count the Number of Cells Containing a Specified String in a Worksheet

This small function counts the number of cells in a worksheet that contain a specified string and outputs a total. Suppose you set the string to = “”. The function counts the number of cells in the sheet that contain anything?you simply insert it into a module:

Option ExplicitDim max_column_number As LongDim max_row_number As LongDim counter As LongDim x As LongDim y As LongDim checkstring As StringFunction GetNotBlankCellCount(max_column_number, max_row_number, checkstring)    counter = 0    For x = 1 To max_column_number 'this is equal to the maximum number of columns you want to check        For y = 1 To max_row_number 'this is equal to the maximum number of rows you want to check                        If checkstring = "" Then                                If Not Sheet1.Cells(x, y) = "" Then 'change sheet1 to your sheet name                    counter = counter + 1                End If                            Else                If Sheet1.Cells(x, y) = checkstring Then 'change sheet1 to your sheet name                    counter = counter + 1                End If            End If                                Next y    Next x        GetNotBlankCellCount = counterEnd Function
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

technology leadership

Why the World Needs More Technology Leadership

As a fact, technology has touched every single aspect of our lives. And there are some technology giants in today’s world which have been frequently opined to have a strong influence on recent overall technological influence. Moreover, those tech giants have popular technology leaders leading the companies toward achieving greatness.

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job