Checking cells values

djbubu99

New Member
Joined
Mar 30, 2011
Messages
15
I have 2 cells with values and I want to check if the first 4 characters of those cells are the same.

My code is:

Code:
Sub ZFVsZT()

If Range("E3").Formula = "=left(E2,4)" <> Range("G3").Formula = "=left(G2,4)" Then
MsgBox "Check values for ZF & ZT"
End If

End Sub

I know this must be a simple thing, but I can't seem to get to the bottom of it..

I need to do this through VBA as a final check on the file that a user will submit to an access database.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Do you mean something like

Code:
Sub ZFVsZT()

If Range("E3").Value <> Left(Range("E2").Value, 4) Or Range("G3").Value <> Left(Range("G2").Value, 4) Then
    MsgBox "Check values for ZF & ZT"
End If

End Sub
 
Upvote 0
thanks for the help!

the code i needed is:

Code:
Sub ZFVsZT()

If Left(Range("E2").Value, 4) <> Left(Range("G2").Value, 4) Then
    MsgBox "Check values for ZF & ZT"
End If

End Sub

I didn't know I can use Left function that way inside of VBA code.

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,242
Members
452,898
Latest member
Capolavoro009

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