VBA How to verify if a selection of cells corresponds to a certain value?

Klash Ville

Board Regular
Joined
Sep 19, 2017
Messages
83
Hello everyone, I have the following problem where I need to verify if a selection of cells corresponds to a certain value.

Here's the screenshot of the problem, and when I run that code, it doesn't work as supposed to, although, I don't know other alternatives:

Ignore the fact I have = "B", it's supposed to be <> "B", I just placed = for the sake of testing...
The problem is in the "ActiveCell.Value" because I got a selection, so, what should I use instead?

4f72b9993154fde7cd97a138b3767417.png
 
Last edited:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You have been on this forum a while.

You should have seen how we like code shown here.

Post the code here and not as a image.
 
Upvote 0
You have been on this forum a while.

You should have seen how we like code shown here.

Post the code here and not as a image.

The problem of the code is clearly on a single line;
The screenshots helps seeing the whole picture of the situation way more easier including the excel cells itself in the context of the code, which is right next to the code itself;

But sure, I can post it:

Code:
With ActiveSheet.ListObjects("Table2")        
      .Range.AutoFilter Field:=.ListColumns("Type").Index, Criteria1:="=B"
End With
    
Range("Table2[Type]").Select
If ActiveCell.Value <> "B" Then
      MsgBox "No results have been found in the filtering of 'B' in Column 'Type'..."
Else
      Selection.Value = "Battery"
End If
 
Last edited:
Upvote 0
Well you did not provide the whole script.
And have not said what your trying to do so I will let someone else help you.
Take care.
 
Upvote 0
Well you did not provide the whole script.
And have not said what your trying to do so I will let someone else help you.
Take care.

Why should I provide a whole script with like 700 lines when my problem happens in 1 line?

It's not my fault that you are in a bad mood, but I HAVE explained my problem in my post, care to read this time?

"Hello everyone, I have the following problem where I need to verify if a selection of cells corresponds to a certain value."

I literally have the debugger on the line that throws away the unexpected result (Yellow arrow), and I even mentioned in that same post and line that the problem is clearly on the ActiveCell.Value

If you don't want to help me, and instead wish to waste my time on this chit-chat, then get lost buddy.
 
Last edited:
Upvote 0
Since you have failed in providing an asnwer of any kind, I just found myself a even better solution among all the some sources I decided to mix up into this final result, which actually even improves the overall perfomance:

This also increases my flexibility among multiple sheets and how many values or strings I wish to detect into a even better and more dinamyc IF filter

Code:
    If Evaluate(WorksheetFunction.CountIf(Sheets("Calculation").Range("Table2[Type]"), "B")) > 1 Then
        MsgBox "No results have been found in the filtering of 'B' in Column 'Type'..."
    Else
        Selection.Value = "Battery"
    End If

Thanks for nothing :laugh:
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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