• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Convert Formula to VBA

Nu2Java

Member
Hello,

I want to convert these formulas to a VBA method. I am not very good with formulas but I am much better with VBA. Can someone help me convert this to VBA? I plan to create a userform with text boxes to validate the data the same way. Thanks for any help.

Code:
=IF(AND(D4="",E4=""),"",IF(RIGHT(D4,6)=RIGHT(E4,6),"PASS","FAIL"))

=IF(AND(E4=""),"",IF(LEFT(E4,19)=$O$3,"PASS","FAIL"))

"O3" RD-FA3622-01 1UL05
"E4" RD-FA3622-01 1UL05 288139
"D4" 1248-20 288139
 
Which cell are you putting the formula in? Either way edit the range accordingly

Code:
Sub Formulator()

'=IF(AND(D4="",E4=""),"",IF(RIGHT(D4,6)=RIGHT(E4,6),"PASS","FAIL"))
Range("A1").Formula = "=IF(AND(D4="""",E4=""""),"""",IF(RIGHT(D4,6)=RIGHT(E4,6),""PASS"",""FAIL""))"

'=IF(AND(E4=""),"",IF(LEFT(E4,19)=$O$3,"PASS","FAIL"))
Range("A2").Formula = "=IF(AND(E4=""""),"""",IF(LEFT(E4,19)=$O$3,""PASS"",""FAIL""))"


End Sub
 
Which cell are you putting the formula in? Either way edit the range accordingly

Code:
Sub Formulator()

'=IF(AND(D4="",E4=""),"",IF(RIGHT(D4,6)=RIGHT(E4,6),"PASS","FAIL"))
Range("A1").Formula = "=IF(AND(D4="""",E4=""""),"""",IF(RIGHT(D4,6)=RIGHT(E4,6),""PASS"",""FAIL""))"

'=IF(AND(E4=""),"",IF(LEFT(E4,19)=$O$3,"PASS","FAIL"))
Range("A2").Formula = "=IF(AND(E4=""""),"""",IF(LEFT(E4,19)=$O$3,""PASS"",""FAIL""))"


End Sub

Hello @chirayu Thanks for your reply. I'm sorry I did not explain this properly. The data that is now in O3, D4, E4 will become the contents of a VBA userform textboxes. I need a VBA solution to perform the "Pass" "Fail" result. I hope I am explaining it properly.
 
Something like this? The reason the second argument shows fail is because LEFT(E4,19) leads to a space at the end so not exact match to O3
 

Attachments

  • Sample.xlsm
    20.8 KB · Views: 2
Something like this? The reason the second argument shows fail is because LEFT(E4,19) leads to a space at the end so not exact match to O3

Ahh yes this is getting me in the right direction. Now all I need is the cell data to be inside of textboxes and then compare the textbox data. There will be no data in the excel sheet. Everything will be in a form.
 
Back
Top