Check if value exists in a range (simple TRUE/FALSE needed)

bukimi

Board Regular
Joined
Apr 12, 2017
Messages
105
Office Version
  1. 2019
Platform
  1. Windows
Hello!

I have a database, which consists of thousands of rows (10-50k rows) and I need to alter value in one column if 3 different conditions are met for that row at the same time (linked by "AND").
For first two I have it easy, because it simply checks if value is "Modem" or not and second one is similar.

Third column is a number, like "14525" and I have a separate file (let's call it List.xls), where one column is a short list of possible (correct) numbers.
I need to check if number in my database is one of numbers on the list, so it can be used in my "If" code.

Currently it looks more or less like this:
Rich (BB code):
Dim lastrow As Long
Dim sht As Worksheet


Set sht = ActiveWorkbook.ActiveSheet
lastrow = sht.Cells.Find("*", SearchOrder:=xlByRows, searchdirection:=xlPrevious).Row


With Sheets("Arkusz1")
    For i = 2 To lastrow
        If .Cells(i, 1) = "Equipment" And .Cells(i, 22) = "Modem" And .cells(i,21)'/IS A VALID NUMBER (from a seperate list) Then
        .Cells(i, 1) = "Other stuff"
    Next i
End With

VLOOKUP seems not suitable here, because it returns a value, not True/False.

By the way, is there a faster way to loop that condition over all these rows than simple for-next loop?

Thank you in advance for all help!
 
Last edited:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
set your list range to a variable and use a worksheet function to check if the cell value matches a list item.
Example:
Code:
Dim rng As Range
Set rng = Sheets(2).Range("myList") 
If .Cells(i, 1) = "Equipment" And .Cells(i, 22) = "Modem" And Appliction.CountIf(rng, .cells(i,21).Value) > 0 Then
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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