VBA Check If Variable Exists in a Column

ckp90c

New Member
Joined
Dec 22, 2016
Messages
11
Hi all,

Just a question about checking if a variable exists in a certain column.

I want to find out if a variable is located in Column A in another sheet.

I have an If statement that currently says below...

If VARIABLE <> "" Then

Output.Cells(m, 1) = xxx
Output.Cells(m, 2) = yyy
Output.Cells(m, 3) = zzz


However, I would rather it check if the Variable is in a range of cells instead.

Is there an easy way to do this?

Thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Depends or how your variable is in the cells and what the data type is in some cases. But here are a couple of ways.
Code:
If Application.CountIf(Range("A:A"), variable) > 0 Then 'if it is a stand alone value
 MsgBox "It's there"
End If
Dim c As Range
For Each c In Range("A:A")
 If InStr(c.Value, variable) > 0 Then 'Embeded in other data
  MsgBox "It's there"
 End If
Next
End If
 
Upvote 0

Forum statistics

Threads
1,214,858
Messages
6,121,956
Members
449,057
Latest member
FreeCricketId

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