VBA Help - If statement equal to a range of cells.

danjames11

New Member
Joined
Apr 22, 2009
Messages
14
I have a range of cells going from B13 all the way to B400. I know how to write this:

If ActiveCell = Range ("B13,B14,B15,B16,B18,and so on") Then....

But I want to be able to do something like B13:B14 instead of writing all the way to 400, But B13:B400 does not work.

Anyone know how to do this.. Once again, I want to see if the active cell is equal to any of the cells in the the range B13 To B400.

Thanks.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try

Code:
If IsNumeric(Application.Match(ActiveCell.Value, Range("B13:B400"), 0)) Then
 
Upvote 0
Are you sure you have a match? I tried VoG's suggestion and it worked.

Just as a test, let's say your active cell is D7, have you tried the Match formula in your worksheet to see what it returns?

Code:
=MATCH(D7,B13:B401,0)

If you have a match it will return a number, otherwise you'll get the #N/A error. If I had to guess, I'm thinking you don't have a match eventhough you think you do (leading or trailing spaces perhaps or you're dealing with a number formatted as a number in one cell and a number formatted as text in the other).
 
Upvote 0
Ahh right, yeah its working now:) Many thanks to you, I'm not sure why I didnt seem to get it to work in the first place but its fine now. You'r very talented and thanks alot!
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,962
Latest member
Fenes

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