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
 

Some videos you may like

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

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.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,568
Messages
5,512,099
Members
408,880
Latest member
FrankHH

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top