+ Reply to Thread
Results 1 to 19 of 19

"Evaluate" VBA function

  1. #1
    Registered User
    Join Date
    04-05-2020
    Location
    USA
    MS-Off Ver
    Windows 10
    Posts
    9

    "Evaluate" VBA function

    Hello. I am new to VBA and would appreciate some help.

    I am writing a simple VBA program to determine if a range of cells has text or a number. Then populate another range of cells (same worksheeet) with the results.

    Conditionals: If the cell is text then I want the cell = empty. If the cell is a number then I want the cell to return a 1 if value >0.85 or a 0 if value < 0.85.

    The cells to evaluate are: A1 to AS60
    The output cells are: AU1 to CM60


    Please Login or Register  to view this content.
    Error: "Expected: end of statement"

    I've been struggling with this error for awhile and would appreciate some help.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,633

    Re: "Evaluate" VBA function

    try change to
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-05-2020
    Location
    USA
    MS-Off Ver
    Windows 10
    Posts
    9

    Re: "Evaluate" VBA function

    Hello. Thank you for your message.

    I tried changing the line to
    Please Login or Register  to view this content.
    but I am still getting the error "Compile Error: Expected: end of statement"

    Should the line read "su60" or "AS60"? I tried both and they both give the same error.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    A bit confusing between the Range.Formula property in order so allocate a formula to a range
    and the Evaluate function (a VBA help must read !) which calculates a formula without using any formula in a range !
    And as you forgot to double each double quote within the string formula …

    So for the formula in a range : [AU1:CM60].Formula = "=IF(ISTEXT(A1),"""",(A1>=0.85)*1)"

    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,633

    Re: "Evaluate" VBA function

    Should be...
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Or try this …


    But if you want only the result the VBA beginner easy way :

    PHP Code: 
    With [AU1:CM60]
        .
    Formula "=IF(ISTEXT(A1),"""",(A1>=0.85)*1)"
        
    .Formula = .Value2
    End With 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » !

  7. #7
    Registered User
    Join Date
    04-05-2020
    Location
    USA
    MS-Off Ver
    Windows 10
    Posts
    9

    Re: "Evaluate" VBA function

    Hello. Thank you very much for the help. I was able to get the program to work (!) using
    Please Login or Register  to view this content.
    For some reason I couldn't get
    Please Login or Register  to view this content.
    to output the values in the cells. But the original error was gone.

  8. #8
    Registered User
    Join Date
    04-05-2020
    Location
    USA
    MS-Off Ver
    Windows 10
    Posts
    9

    Re: "Evaluate" VBA function

    Hi. I am trying to subtract 2 ranges of cells that are on the same worksheet and output the results in a range of cells.

    Input ranges are: (A1 to AS58) and (AU1 to CM58)
    Output range is: (CO1:EG58)
    Conditional: if any of the inputs are text, put an empty space in the cell

    I am using this line of code:
    Please Login or Register  to view this content.
    The output CO1:EG58 shows #VALUE!.

    Could you please tell me if my line of code is correct?

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,633

    Re: "Evaluate" VBA function

    Perhaps
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    04-05-2020
    Location
    USA
    MS-Off Ver
    Windows 10
    Posts
    9

    Re: "Evaluate" VBA function

    Thank you jindon. That works!

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,633

    Re: "Evaluate" VBA function

    OK,
    Evaluate method;

    Evaluate("1+1") equivalent to [1+1] [] are the sort cut notation of Evaluate method.
    Difference is Evaluate accepts variables while [] can only accepts static string, so
    Please Login or Register  to view this content.
    As you can see the difference, you can use [] with the formula used in the cell as it is.
    Subscript of Evaluate needs to be surrounded by double quotes.

    Please Login or Register  to view this content.
    HTH
    Last edited by jindon; 04-05-2020 at 11:54 PM.

  12. #12
    Registered User
    Join Date
    04-05-2020
    Location
    USA
    MS-Off Ver
    Windows 10
    Posts
    9

    Re: "Evaluate" VBA function

    Thank you jindon for the information regarding Evaluate and [].

    I am struggling with another issue.

    I have one worksheet in one file that I would like to copy into another worksheet in another file.

    The code that I have below gives me the error: "Script out of range"

    Please Login or Register  to view this content.
    It correctly converts the .csv file to .xlsx.
    However, it gets hung-up right after the line ActiveWorkbook.SaveAs

    I would appreciate help with this.

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,633

    Re: "Evaluate" VBA function

    OK.
    Evaluate method doesn't work across workbooks.

    Few alternatives and the easiest way is to pace a formula but only if you know full and the worksheet name and the range.
    Please Login or Register  to view this content.
    TEK-CMOS-56_microscope_csv.xlsx need not to be open.

  14. #14
    Registered User
    Join Date
    04-05-2020
    Location
    USA
    MS-Off Ver
    Windows 10
    Posts
    9

    Re: "Evaluate" VBA function

    Thank you jindon for your message above. I'm having trouble understanding how to implement your code.
    It might be easier for me if I use simpler file names.

    File #1 is test1.xls with Worksheet1: it has cells A1:AS59
    File #2 is test2.xls with Worksheet2: copy test1.xls into test2.xls starting at location CO1

    I tried this code below and it gives me a "Subscript out of Range" error. I'm sorry but I can't figure out how to correct this based on your example above

    Please Login or Register  to view this content.

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,633

    Re: "Evaluate" VBA function

    You can't do like that.
    If both workbooks are open
    Please Login or Register  to view this content.
    By the way. file extension is XLSX, not XLXS.

  16. #16
    Registered User
    Join Date
    04-05-2020
    Location
    USA
    MS-Off Ver
    Windows 10
    Posts
    9

    Re: "Evaluate" VBA function

    Thank you jindon. I was able to get the expression to work with "Workbooks.Open" instead of just "Workbooks" and making your correction "xlsx".

    I am having another problem with subtracting a range of cells in the same worksheet, in particular the ranges: (AU1:CM60) - (CO1:EF60)

    I am trying the line of code below but it is giving me incorrect values in the cells. Would you have a suggestion how to correct?

    Please Login or Register  to view this content.

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,633

    Re: "Evaluate" VBA function

    (AU1:CM60) - (CO1:EF60)

    Number of columns are different.

  18. #18
    Registered User
    Join Date
    04-05-2020
    Location
    USA
    MS-Off Ver
    Windows 10
    Posts
    9

    Re: "Evaluate" VBA function

    Thank you jindon. It works now.

  19. #19
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,730

    Re: "Evaluate" VBA function

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 5
    Last Post: 02-05-2019, 12:03 AM
  2. [SOLVED] Column X-Ref list - Sheet1 Col A "pages", Col B:FL "Req" to Sheet2 ColA "req", ColB "page"
    By excel-card-pulled in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-07-2017, 09:30 AM
  3. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  4. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  5. VBA Evaluate Formula and "Copy Down" Result as String/Value to Last Row
    By falkon007 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-22-2013, 03:04 AM
  6. Using DMIN to evaluate "less than" or "greater than" a specific date
    By williams485 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-01-2012, 12:45 PM
  7. Please add a "sheet" function like "row" and "column" functions
    By Spreadsheet Monkey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-08-2005, 12:15 PM

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