Find something not equal

rjwebgraphix

Well-known Member
Joined
May 25, 2010
Messages
590
Is there a way to find something that is not equal to a value or is the best bet still this looped if statement?

Code:
Dim HdrRng As Range
Dim BadFile As Boolean
Dim MixedPlnt As Boolean.
 
Set HdrRng = Rows("4:4")
Set PlntFound = HdrRng.Find("Plnt", [A4], , xlWhole, xlByColumns, xlPrevious)
    If Not PlntFound Is Nothing Then
        PlntCol = HdrRng.Find("Plnt", [A4], , xlWhole, xlByColumns, xlPrevious).Column
 lrow = 6
 Do While Cells(lrow, PlntCol) <> ""
     Cells(lrow, PlntCol).Value = RTrim(Cells(lrow, PlntCol))
     If Cells(lrow, PlntCol) <> 520 Or Cells(lrow, PlntCol) <> 520 Then
         MixedPlnt = True
         Exit Do
     End If
 lrow = lrow + 1
 Loop
    Else
        BadFile = True
    End If

I'm primarily talking about this section....

Code:
 Do While Cells(lrow, PlntCol) <> ""
     Cells(lrow, PlntCol).Value = RTrim(Cells(lrow, PlntCol))
     If Cells(lrow, PlntCol) <> 520 Then
         MixedPlnt = True
         Exit Do
     End If
 lrow = lrow + 1
 Loop

Just with 16000 rows, it takes a while and looking for a faster way.

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
A really easy way to make your run code faster is to add
Application.ScreenUpdating = False
in front of your code

and Application.ScreenUpdating = True at the end of your code.

And the reason why your code takes so long is because your find function, which searches a match in the whole worksheet.
If you can, toning down on your search area is recommended.
 
Upvote 0
And the reason why your code takes so long is because your find function, which searches a match in the whole worksheet.
If you can, toning down on your search area is recommended.

The find is plenty speedy, it's only looking on row 4 anyway to determine if it finds the right header label as well as which column the header label is in.

What takes so long is having to loop through 16000 rows of data to see if any of the rows have a value that is not 520.

If Cells(lrow, PlntCol) <> 520 Then

I was just hoping there was a way to do a find to see any value in that Column (PlntCol) is not 520.
 
Upvote 0

Forum statistics

Threads
1,214,560
Messages
6,120,217
Members
448,951
Latest member
jennlynn

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