Find something not equal

rjwebgraphix

Well-known Member
Joined
May 25, 2010
Messages
588
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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

kpark91

Well-known Member
Joined
Jul 15, 2010
Messages
1,582
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.
 

rjwebgraphix

Well-known Member
Joined
May 25, 2010
Messages
588
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,453
Messages
5,837,355
Members
430,496
Latest member
Steph_88

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
Top