Table of Contents
VBA, or Visual Basic for Applications, is a programming language commonly used in Microsoft Excel to automate tasks and manipulate data. One task that may frequently arise is the need to find a specific value in a column of data. This can be accomplished using VBA through the use of the FIND function. By specifying the search criteria and the target column, the FIND function will return the location of the first occurrence of the specified value. This allows for efficient and accurate searching within large datasets, saving time and effort for the user. The FIND function in VBA is a powerful tool that can greatly enhance the functionality and usability of Excel for data analysis and management.
VBA: Find Value in Column (With Example)
You can use the following basic syntax in VBA to find a value in a column in Excel:
Sub FindValue()
Dim rng As Range
Dim cell As Range
Dim findString As String
'specify range to look inSet rng = ActiveSheet.Columns("A:A")
'specify string to look for
findString = "Rockets"
'find cell with stringSet cell = rng.Find(What:=findString, LookIn:=xlFormulas, _
LookAt:=xlWhole, MatchCase:=False)
If cell Is Nothing Then
cell.Font.Color = vbBlack
Else
cell.Font.Color = vbRed
cell.Font.Bold = True
End IfEnd Sub
This particular macro will look for the string “Rockets” in all of column A of the currently active sheet and, if found, change the font color of the cell to red and make the font bold.
The following example shows how to use this syntax in practice.
Example: How to Find Value in Column Using VBA
Suppose we have the following dataset that contains information about various basketball players:

Suppose we would like to find the team name “Rockets” in column A and, when found, convert the font color of the cell to red and make the font bold.
We can create the following macro to do so:
Sub FindValues()
Dim rng As Range
Dim cell As Range
Dim findString As String
'specify range to look inSet rng = ActiveSheet.Columns("A:A")
'specify string to look for
findString = "Rockets"
'find cell with stringSet cell = rng.Find(What:=findString, LookIn:=xlFormulas, _
LookAt:=xlWhole, MatchCase:=False)
If cell Is Nothing Then
cell.Font.Color = vbBlack
Else
cell.Font.Color = vbRed
cell.Font.Bold = True
End IfEnd SubWhen we run this macro, we receive the following output:

Notice that the font in the cell with the string “Rockets” is now red and bold.
All other cells simply kept their black font.
Note that the argument MatchCase:=False in the code tells VBA to perform a case-insensitive search.
Thus, if the team name in column A was “rockets” then the macro would still find this string and make the font red and bold.
Cite this article
stats writer (2024). How can I find a specific value in a column using VBA?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-find-a-specific-value-in-a-column-using-vba/
stats writer. "How can I find a specific value in a column using VBA?." PSYCHOLOGICAL SCALES, 24 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-find-a-specific-value-in-a-column-using-vba/.
stats writer. "How can I find a specific value in a column using VBA?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-find-a-specific-value-in-a-column-using-vba/.
stats writer (2024) 'How can I find a specific value in a column using VBA?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-find-a-specific-value-in-a-column-using-vba/.
[1] stats writer, "How can I find a specific value in a column using VBA?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I find a specific value in a column using VBA?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
