pctechguide.com

  • Home
  • Guides
  • Tutorials
  • Articles
  • Reviews
  • Glossary
  • Contact

VBA Macro that Counts the Number of Cells Starting with a Given Letter

There many be times when you need to know how many words start with a given letter. You can easily accomplish this with VBA. We created a VBA macro that lets you do this.

The macro that we developed to do this is shown below.

The Macro that Lets You Count How Many Words Start with a Given Letter

To use this letter, you need to copy and paste the list of words in Column A. Then you need to show the letter that you want to count in column B.

You will need to run the macro by copying it into the Visual Basic editor, which can be found under the Developer tab. You will need to click Insert Module first. Then, click the run button or push F11.

Sub CountCellsStartingWithLetter()
Dim ws As Worksheet
Dim lastRow As Long
Dim letter As String
Dim count As Integer
Dim cell As Range

‘ Set the worksheet
Set ws = ThisWorkbook.Sheets(“Sheet1”) ‘ Change “Sheet1” to your sheet name

‘ Find the last row with data in column B
lastRow = ws.Cells(ws.Rows.Count, “B”).End(xlUp).Row

‘ Prompt user to enter the letter
letter = InputBox(“Enter the letter to count cells starting with:”, “Letter Input”)

‘ Validate input
If Len(letter) <> 1 Then
MsgBox “Please enter only one letter.”, vbExclamation
Exit Sub
End If

‘ Convert letter to uppercase
letter = UCase(letter)

‘ Reset count
count = 0

‘ Loop through each cell in column B
For Each cell In ws.Range(“B1:B” & lastRow)
‘ Check if the cell starts with the specified letter
If UCase(Left(cell.Value, 1)) = letter Then
count = count + 1
End If
Next cell

‘ Display the count
MsgBox “Number of cells starting with ‘” & letter & “‘: ” & count, vbInformation
End Sub

Can You Do this Without VBA?

You can still count the number of words starting with a given letter without using VBA. However, you will need to do so in a more roundabout way. The best way to do this is by sorting the column and then copying and pasting all words that you see with the given letter into the first cell in another column. Then, you can see how many rows are filled. You will have to use the undo command or clear the column after. 

This will take less time if you are just doing it once. However, you may want to use VBA if you plan on counting cells like this more frequently. 

We hope this helps!

Filed Under: Articles

Latest Articles

How to Remove Unlimited Defender

THREAT OVERVIEW: Unlimited Defender is a fake security application that has been designed by cyber criminals with the objective of stealing money from unsuspecting users. This is not a real security client reason why once detected it is recommended to conduct all the necessary steps to … [Read More...]

fbi moneypak virus

FBI Money Pak Virus

FBI MoneyPak is a malware client that holds your computer for ransom until you pay a fine. As stated this is malware, a computer virus that infected your computer and is now attempting to trick you into paying a false fine. The makers of this malware have been at it for a while. There are dozens of … [Read More...]

Disk Maintenance – The Disk Defrag

When most people want to purchase a new computer or upgrade their current one, they focus on finding a CPU with the quickest speed, the most computing cores, or the most RAM they can afford. However, they may be overlooking the most likely reason for computing slowdowns: Â fragmentation in the … [Read More...]

Gaming Laptop Security Guide: Protecting Your High-End Hardware Investment in 2025

Since Jacob took over PC Tech Guide, we’ve looked at how tech intersects with personal well-being and digital safety. Gaming laptops are now … [Read More...]

20 Cool Creative Commons Photographs About the Future of AI

AI technology is starting to have a huge impact on our lives. The market value for AI is estimated to have been worth $279.22 billion in 2024 and it … [Read More...]

13 Impressive Stats on the Future of AI

AI technology is starting to become much more important in our everyday lives. Many businesses are using it as well. While he has created a lot of … [Read More...]

Graphic Designers on Reddit Share their Views of AI

There are clearly a lot of positive things about AI. However, it is not a good thing for everyone. One of the things that many people are worried … [Read More...]

Redditors Talk About the Impact of AI on Freelance Writers

AI technology has had a huge impact on our lives. A 2023 survey by Pew Research found that 56% of people use AI at least once a day or once a week. … [Read More...]

11 Most Popular Books on Perl Programming

Perl is not the most popular programming language. It has only one million users, compared to 12 million that use Python. However, it has a lot of … [Read More...]

Guides

  • Computer Communications
  • Mobile Computing
  • PC Components
  • PC Data Storage
  • PC Input-Output
  • PC Multimedia
  • Processors (CPUs)

Recent Posts

Updated List of Cybersecurity Best Practices for 2019

Online scams are becoming frighteningly common. The FBI released a report in 2018 showing that losses from online scams exceeded $1.4 billion the … [Read More...]

Windows Backup Restoration

Click Start, point to All Programs > Accessories > System Tools, and then click Backup. The Backup or Restore Wizard is … [Read More...]

Recover My Files Review

  This is PC Tech's number one choice for data recovery! As far as all around data recovery software goes, Recover My Files would have … [Read More...]

[footer_backtotop]

Copyright © 2025 About | Privacy | Contact Information | Wrtie For Us | Disclaimer | Copyright License | Authors