Help converting IF NOT OR AND to VBA IF statement

Joyner

Well-known Member
Joined
Nov 15, 2005
Messages
1,202
Hello everyone, I am trying to convert the below working IF to VBA:

Code:
=NOT(OR(AND(LEFT($C6,1)="T",LEN($C6)=9,ISNUMBER(-RIGHT($C6,8))),AND(ISNUMBER(-$C6),LEN($C6)=9)))

What I have tried is:

Code:
  [FONT=Calibri][SIZE=3][COLOR=#000000]If Not ((Left(Cells(i + 1, 3), 1).Value = "T" AndLen(Cells(i + 1, 3)) = 9 And IsNumeric(-Right(Cells(i + 1, 3), 8))) Or(IsNumeric(-Cells(i + 1, 3)) And Len(Cells(i + 1, 3)) = 9)) Then [/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=3][COLOR=#000000][/Co[/COLOR][/SIZE][/FONT]de]

This is giving me a run time error 424 object required.

What am I missing?

Thank you
 
Last edited:
If I am reading your original formula (Message #1 ) correctly, I believe this line of code will also work...

Thank you sir for all of the information. I tried to research how to use "Like" but couldn't figure in out. Because of the way the last nine characters are parsed, the value can be something like _12345678 and all that is acceptable is something like T12345678 or 123456789.

So I adapted yours to

Code:
 If Not (Cells(i + 1, 3) Like "[T]########" Or Cells(i + 1, 3) Like "#########") Then

And that. seems to work.

I couldn't figure out the conditional format thing either so again thanks for all of the information.


P,S. I also abandoned the conditional formatting thing because I thought the code route would be more efficient
 
Last edited:
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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