Results 1 to 3 of 3

Thread: [RESOLVED] macro inserting single quotes???

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Resolved [RESOLVED] macro inserting single quotes???

    I am writing an Excel macro in 2007. I am trying to create a VLOOKUP() formula to insert into a cell. When the formula is inserted into the spreadsheet, the macro is putting single quotes around the cells in the range causing it not to work. I can't figure out why it is doing that.... any ideas?

    Here is the line of code I am using to insert the formula.
    vlookup Code:
    1. Cells(.Row, .Column + 1) = "=VLOOKUP(RC[-1],chart!A2:B" & Format(Sheets("chart").Range("A2").End(xlDown).Row) & ",2,FALSE)"

    And here is what it looks like in the Excel spreadsheet. (Notice the single quotes). It gives a #NAME error. When i remove the single quotes it works fine. I just don't understand why Excel is putting them in to begin with!

    =VLOOKUP(A10,Chart!'A2':'B8812',2,FALSE)

    I'm hoping this is obvious to someone... I cannot figure it out!!

    Thank you for looking!

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: macro inserting single quotes???

    i can not tell you why, but it is an effect of using the rc[-1] part
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: macro inserting single quotes???

    Thank you! I replaced the RC[-1] with an actual cell reference and it works.

    Thank again!

Posting Permissions

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



Click Here to Expand Forum to Full Width