+ Reply to Thread
Results 1 to 3 of 3

VBA Set Cell Gains Extra Quotes

  1. #1
    Registered User
    Join Date
    10-10-2021
    Location
    UK
    MS-Off Ver
    365
    Posts
    1

    VBA Set Cell Gains Extra Quotes

    Hi All

    When I try to set a cell's value to be a vlookup formula such as the following
    Worksheets("Sheet1").Cells(1, 1).Value = "=VLOOKUP(RC[1], Sheet2" & Chr(33) & "B8:G500, 2,false)"

    the value that gets entered into the cell is the following:
    =VLOOKUP(B1, Sheet2!'B8':'G500', 2,FALSE)

    rather than the desired
    =VLOOKUP(B1, Sheet2!B8:G500, 2,FALSE)

    Does anybody know where these quotes come from and how I can set a cell to be a vlookup field without these quotes?

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,966

    Re: VBA Set Cell Gains Extra Quotes

    Don’t mix r1c1 references with a1 style references - use one or the other. I’m not sure why you need to use Chr there at all.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    47,997

    Re: VBA Set Cell Gains Extra Quotes

    Different ways to get what you want:

    Worksheets("Sheet1").Cells(1, 1).FormulaR1C1 = "=VLOOKUP(RC[1], Sheet2!R8C2:R500C7, 2,FALSE)"
    Worksheets("Sheet1").Cells(1, 1).FormulaR1C1 = "=VLOOKUP(RC[1], Sheet2!R[7]C[1]:R[499]C[6], 2,FALSE)"
    Worksheets("Sheet1").Cells(1, 1).Formula = "=VLOOKUP(B1, Sheet2!B8:G500, 2,FALSE)"

    Worksheets("Sheet1").Range("A1:A10").FormulaR1C1 = "=VLOOKUP(RC[1], Sheet2!R8C2:R500C7, 2,FALSE)"
    Worksheets("Sheet1").Range("A1:A10").FormulaR1C1 = "=VLOOKUP(RC[1], Sheet2!R8C[1]:R500C[6], 2,FALSE)"
    Worksheets("Sheet1").Range("A1:A10").Formula = "=VLOOKUP(B1, Sheet2!$B$8:$G$500, 2,FALSE)"
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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. [SOLVED] Convert Excel sheet to text file without extra quotes in my data file
    By chi05 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-11-2021, 10:10 PM
  2. Reading in csv file where there are quotes in records and extra commas
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-17-2015, 01:25 PM
  3. [SOLVED] Double Quotes using Chr(34) and Extra Quotes when saving as text file
    By vamosj in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-26-2013, 12:26 PM
  4. Replies: 8
    Last Post: 08-27-2012, 04:37 PM
  5. Replies: 2
    Last Post: 07-29-2009, 11:06 AM
  6. Setting a cell's value as a formula containing quotes or double quotes using vba
    By Metshrine in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-09-2006, 04:10 AM
  7. saving as text adding extra quotes?
    By Corey Wirun in forum Excel General
    Replies: 2
    Last Post: 05-13-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