multiple search criteria

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
I have this code that searches a list for "Deposit". I would like to search for Deposit & Withdrawal. How can I adjust this code to accomplish this task.

Thank you kindly for your help...


Code:
Do Until Cells(RowNum, 19).Value = ""    If InStr(1, Cells(RowNum, 20).Value, "Deposit", vbTextCompare) > 0 Then
        Cells(SRow, 23).Value = Cells(RowNum, 19).Value
        Cells(SRow, 24).Value = Cells(RowNum, 20).Value
        Cells(SRow, 25).Value = Cells(RowNum, 21).Value
        SRow = SRow + 1
    End If
    RowNum = RowNum + 1
Loop
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
hi,
Try

Code:
Do Until Cells(RowNum, 19).Value = ""
If Not IsError(Application.Match(Cells(RowNum, 20).Value, Array("Deposit", "Withdrawal"), 0)) Then
        Cells(SRow, 23).Value = Cells(RowNum, 19).Value
        Cells(SRow, 24).Value = Cells(RowNum, 20).Value
        Cells(SRow, 25).Value = Cells(RowNum, 21).Value
        SRow = SRow + 1
    End If
    RowNum = RowNum + 1
Loop

Dave
 
Upvote 0
Thank you dmt32 for the quick response and assistance.

Just our of curiosity and continued education, I'm no expert, however, looping large data-set can be time-consuming. Is there a better way to right this code?

Again thank you for you help
 
Upvote 0
Thank you dmt32 for the quick response and assistance.

Just our of curiosity and continued education, I'm no expert, however, looping large data-set can be time-consuming. Is there a better way to right this code?

Again thank you for you help

Hi,
glad suggestion helped.

Writing to each cell in a large data-set in a loop is not the most efficient method - depending on what you are doing, building an array & then writing to the ranges in one go would be a better approach.

If you have issues with speed in your code, post a new question & all your code - plenty here to offer guidance.

Dave
 
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,785
Members
449,095
Latest member
m_smith_solihull

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