+ Reply to Thread
Results 1 to 4 of 4

Correct syntax for replace command

  1. #1
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,919

    Correct syntax for replace command

    Here is the code
    Please Login or Register  to view this content.
    I get a syntax error on both of the attempted Replace commands. What is the correct syntax?
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,919

    Re: Correct syntax for replace command

    Never mind, I got it I have to make a dummy Boolean value to assign the return to.

    RTN = Range("Table_Shortage_Report").Replace("(blank)","")

    Where RTN is defined as Boolean/

  3. #3
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: Correct syntax for replace command

    Quote Originally Posted by dflak View Post
    Range("Table_Shortage_Report").Replace("(blank)","")
    Actually, your problem is with your use of parentheses. This would work fine...

    Range("Table_Shortage_Report").Replace "(blank)", ""

    but when you surrounded the arguments in parentheses, VBA attempted to do what it always does with parentheses that are not required by syntax... it attempted to evaluate the contents of the parentheses in order to produce a single value. For subroutines and methods (Replace is a method), parentheses are not required for by syntax. If there is just a single argument, surrounding it with parentheses is not a problem (a value evaluates to itself); however, when there is two or more arguments, surrounding them with parentheses asks VBA to create a single evaluated value from them... that can't be done because, well, there are two or more independent values and VBA can't evaluate them into a single value so it raises an error instead. By the way, your solution method worked because you used Replace as a function (which it is designed to act as if desired) and functions require parentheses around its argument list by syntax.
    Last edited by Rick Rothstein; 04-19-2021 at 06:56 PM.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: Correct syntax for replace command

    And in your first post there is a spelling error that has been changed I assume (what:="(balnk)"
    If you copied the code from your Module, that would raise an error also

+ 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. Correct syntax using IF and AND
    By Illona in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-22-2014, 06:43 PM
  2. What is the correct syntax?
    By LLL0422 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-05-2014, 06:21 PM
  3. Help getting my syntax correct
    By MMS6300 in forum Excel - New Users/Basics
    Replies: 8
    Last Post: 02-20-2009, 02:26 PM
  4. Correct syntax
    By Paragons in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-07-2007, 07:48 AM
  5. CORRECT SYNTAX FOR RUN...
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2006, 07:39 PM
  6. Correct VBA syntax
    By Ken G. in forum Excel General
    Replies: 3
    Last Post: 12-06-2005, 08:40 PM
  7. [SOLVED] If...and... - can never get the syntax correct!
    By Darin Kramer in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-24-2005, 01:06 PM

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