+ Reply to Thread
Results 1 to 24 of 24

String Function not working when an IF statement is present

  1. #1
    Registered User
    Join Date
    08-20-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2012
    Posts
    24

    String Function not working when an IF statement is present

    String Function .xlsm

    I have a large pricing spreadsheet that chooses the correct pricing formula based on the part number. I have inserted a basic version. The string function works great when pulling over the pricing formula as long as it doesn't contain a FUNCTION name, ie. IF. I need help working around this problem.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: String Function not working when an IF statement is present

    it's nothing to do with the IF functions-evaluate only works with strings up to 255 characters
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    08-20-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2012
    Posts
    24

    Re: String Function not working when an IF statement is present

    How should I fix the problem? Do you have any ideas on a work around to bring the correct function over rather than using Evaluate?

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: String Function not working when an IF statement is present

    load the formula into a cell then read the value and clear the cell

  5. #5
    Registered User
    Join Date
    08-20-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2012
    Posts
    24

    Re: String Function not working when an IF statement is present

    How do you do that?

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: String Function not working when an IF statement is present

    right-click the worksheet choose view code and paste this in
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-20-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2012
    Posts
    24

    Re: String Function not working when an IF statement is present

    The VBA code you sent me to read the value and clear the cell looks like it should work. However, it errors out at the If Not Iserror line. I can't seem to read in the code where it it telling it what to do when it does error, only when it's not an error. Help?



    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rCell As Range
    Dim vFormula
    If Not Intersect(Target, Range("C:C")) Is Nothing Then
    Application.EnableEvents = False
    For Each rCell In Intersect(Target, Range("C:C")).Cells
    If Len(rCell.Value) > 0 Then
    vFormula = Application.VLookup(rCell.Value, Sheets("Function examples").Range("A:B"), 2, False)
    If Not IsError(vFormula) Then Cells(Target.Row, "J").Formula = "=" & Replace(vFormula, "|", Target.Row)
    End If
    Next rCell
    Application.EnableEvents = True
    End If
    End Sub

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: String Function not working when an IF statement is present

    what is the exact error?

    also please learn to use code tags as stated in the forum rules ;-)

  9. #9
    Registered User
    Join Date
    08-20-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2012
    Posts
    24

    Re: String Function not working when an IF statement is present

    It didn't give an error message, it just stopped and when I evaluated the formula in the Excel Screen it gave a #REF error in the Vlookup. I tried running it again to see if it would give an error message in the VBA and it didn't.

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: String Function not working when an IF statement is present

    can you post the workbook-I reckon your formula is wrong

  11. #11
    Registered User
    Join Date
    08-20-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2012
    Posts
    24

    Re: String Function not working when an IF statement is present

    Here is the file.
    Attached Files Attached Files

  12. #12
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: String Function not working when an IF statement is present

    yes-you have errors in the formula string. for example
    + (73(G| <= 15,8, 12)
    is part of the formula string. if you replace | for a row number (eg 3) you get
    + (73(G3 <= 15,8, 12)

    I have no idea what that is supposed to do-at a guess it's missing an operator and the IF function

  13. #13
    Registered User
    Join Date
    08-20-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2012
    Posts
    24

    Re: String Function not working when an IF statement is present

    String Function .xlsm

    My apologies. That was an error on my part. Here is the corrected file. I used two new part numbers and their formulas. It is still erring out, however, this time it's the #Value.

  14. #14
    Registered User
    Join Date
    08-20-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2012
    Posts
    24

    Re: String Function not working when an IF statement is present

    I was messing around in the file before trying to understand it and I typed some code in before the END IF. I deleted it and it must not have saved. Your version of the file still contains it.

  15. #15
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: String Function not working when an IF statement is present

    that version of the file works for me (after removing your amendments to the code)

  16. #16
    Registered User
    Join Date
    08-20-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2012
    Posts
    24

    Re: String Function not working when an IF statement is present

    So, for the second part number it returns a price?

  17. #17
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: String Function not working when an IF statement is present

    yes it does $1,808.41

  18. #18
    Registered User
    Join Date
    08-20-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2012
    Posts
    24

    Re: String Function not working when an IF statement is present

    Not seeing why it would work for you and not me. I am working in 2010. Would that have anything to do with it? Will you please send me the corrected file from your end and I will check it on my computer.

  19. #19
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: String Function not working when an IF statement is present

    I have 2010 also. file attached
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    08-20-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2012
    Posts
    24

    Re: String Function not working when an IF statement is present

    I have tried opening it on two different computers and it still will not work. Any suggestions?

  21. #21
    Registered User
    Join Date
    08-20-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2012
    Posts
    24

    Re: String Function not working when an IF statement is present

    I tried again on a different computer and it works fine. Makes me wonder if I have a setting on my program that is stopping it. Thank you for your help. I can go from here.

  22. #22
    Registered User
    Join Date
    08-20-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2012
    Posts
    24

    Re: String Function not working when an IF statement is present

    Joseph,

    I just realized another problem has arisen. The larger spreadsheet that I am using this in requires that I copy and paste the part numbers into Column C, about 5-10 lines at a time. It also includes the info for column D,E, F and G. When I copy the data into the spreadsheet the only price in (J) that calculates correctly is the first line. Then it fails to work on the remaining lines.

  23. #23
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: String Function not working when an IF statement is present

    I goofed-change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    08-20-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2012
    Posts
    24

    Re: String Function not working when an IF statement is present

    Thank you. Works beautifully!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1