<> don't work

Apple1

Board Regular
Joined
Jan 18, 2015
Messages
121
Hi

For some reason, the below code don't work. It shows the error message even when all my filtered rows =base

Thank you

Code:
Option Explicit
 
Sub Macro1()
'
' Macro1 Macro
'
 
'
 
Dim base As Integer
 
Dim c As Range
 
 
 
base = InputBox("State base")
 
ActiveWorkbook.ActiveSheet.Range("A:W").AutoFilter Field:=11, Criteria1:="<>" & 2 * base
 
For Each c In ActiveWorkbook.ActiveSheet.Range("K:K").SpecialCells(xlCellTypeVisible)
 
       If c.Value <> base Then
            Cells(1, 1000) = "ERROR"
            MsgBox "There is an error with the SubTotal. Please change manually."
       Exit For
 
       End If
 
Next
End Sub
 
Last edited by a moderator:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try:
Code:
Option Explicit
Sub Macro1()
    Application.ScreenUpdating = False
    Dim bottomK As Long
    bottomK = Range("K" & Rows.Count).End(xlUp).Row
    Dim base As Integer
    Dim c As Range
    base = InputBox("State base")
    ActiveWorkbook.ActiveSheet.Range("A:W").AutoFilter Field:=11, Criteria1:="<>" & 2 * base
    For Each c In ActiveWorkbook.ActiveSheet.Range("K2:K" & bottomK).SpecialCells(xlCellTypeVisible)
           If c.Value <> base Then
                Cells(1, 1000) = "ERROR"
                MsgBox "There is an error with the SubTotal. Please change manually."
                Exit For
           End If
    Next c
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Just a nit comment. ActiveWorkbook.ActiveSheet is a redundant expression since ActiveSheet would have to be in the active workbook. The code would work just as well if ActiveWorkbook was omitted.
 
Upvote 0
Just a nit comment. ActiveWorkbook.ActiveSheet is a redundant expression since ActiveSheet would have to be in the active workbook. The code would work just as well if ActiveWorkbook was omitted.
You could also get rid of the ActiveSheet as well:)
 
Upvote 0
@Fluff, @JLGWhiz: Thank you. Should have picked up on that.

Agree that it wilol work in this case without the ActiveSheet, but it is good practice to always qualify a range object with the parent sheet so that when more than one sheet is referred to in the code, there is no accidental default to the wrong sheet.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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