Search Multiple Values in Worksheet Data

How to search multiple values in worksheet data using VBA. Earlier we had learnt how to search for data in a worksheet using a looping process but were able to find a single value. Today we learn to extract all the occurrences of data in our worksheet like an item code with VBA. Watch the video below:

Watch this video on YouTube.

Here’s the complete VBA code to find multiple data withe the same value:

Sub searchMultipleValues()
Dim erow As Long
Dim ws As Worksheet
Dim lastrow As Long
Dim count As Integer

lastrow = Sheets(“item_price”).Cells(Rows.count, 1).End(xlUp).Row

count = 0

Dim p As Long

p = 11

For x = 2 To lastrow

If Sheets(“item_price”).Cells(x, 1) = Sheet2.Range(“b3”) Then
Sheet2.Cells(p, 1) = Sheets(“item_price”).Cells(x, 1)
Sheet2.Cells(p, 2) = Sheets(“item_price”).Cells(x, 2)
Sheet2.Cells(p, 3) = Sheets(“item_price”).Cells(x, 3)
p = p + 1
count = count + 1
End If
Next x

MsgBox ” The number of data found for this item code is ” & ” ” & count

If count = 0 Then
Set ws = Worksheets(“Sheet3”)
With ws
erow = .Cells(Rows.count, 1).End(xlUp).Offset(1, 0).Row
.Cells(erow, 1) = Date
.Cells(erow, 2) = Sheet2.Range(“B3”)
End With
End If


End Sub


Published by

Dinesh Kumar Takyar

Welcome to! My aim is to help you learn MS Excel including VBA. I always felt that a good way to learn something was to find solutions to problems in that domain. That is why I share these Excel videos with you. Mostly these are questions asked during my corporate training sessions. I've been training individuals and companies in computers since 1991. I did my B. Sc. (Vordiplom), M. Sc. (Diplom) and Ph.D. (Dr. rer. nat.) from Hamburg, Germany. The best thing about solving some of my visitor's questions is that I also gain new insights. For more Excel VBA solutions you may like to visit my YouTube channel: For a structured Excel VBA training course online you can visit:

3 thoughts on “Search Multiple Values in Worksheet Data”

  1. Hio sir
    if i have a Userform instead of sheet2 how i will get the data from sheet to userform. textbox CboReg is the search textbox
    200 -14.5 100.25
    200 -10.5 100.12
    200 0.000 100.0
    200 2.650 100.325
    200 5.000 100.600

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.