+ Reply to Thread
Results 1 to 5 of 5

VBA Compile Syntax Error when trying to introduce variables

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-01-2008
    Location
    Australia
    Posts
    108

    VBA Compile Syntax Error when trying to introduce variables

    Hi All,
    I am trying to derive a formula for excel.

    Below works.

    Dim Test As String
    'Test = "Car; color=blue;"

    But now I want to add more fields and I do not want them to be fixed. e.g. (Test = "Car; color=blue;Model =Toyota;Year=2002;")

    so I change to

    Dim Test As String
    Dim X As String
    Dim Y As String

    X = Toyota
    Y = 2002

    Test = "Car; color=blue;Model ="X";Year="Y";"

    But I faced synatx error. What could be the issue?

    Any help is appreciated!

    Regards,
    Nironto

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

    Re: VBA Compile Syntax Error when trying to introduce variables

    you've gotta double up the quotes in a string
    Test = "Car; color=blue;Model =""X"";Year=""Y"";"
    Josie

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

  3. #3
    Forum Contributor
    Join Date
    09-01-2008
    Location
    Australia
    Posts
    108

    Re: VBA Compile Syntax Error when trying to introduce variables

    Thanks Joseph P for your help!

    But what I got now was below when I do a mouse over:
    Test = "Car; color=blue;Model ="X";Year="Y","

    What I wanted was (Without hardcoding the values)
    Test = "Car; color=blue;Model=Toyota;Year=2002,"

    Here is the formula. Sorry, I am a beginner and am trying to pick things up.

    Sub OPC()
    Dim Test As String
    Dim X As String
    Dim Y As String

    X = "Toyota"
    Y = "2002"

    Test = "Car; color=blue;Model =""X"";Year=""Y"";"
    End Sub

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

    Re: VBA Compile Syntax Error when trying to introduce variables

    my bad-I misunderstood
    Test = "Car; color=blue;Model =" & X & ";Year=" & Y & ";"

  5. #5
    Forum Contributor
    Join Date
    09-01-2008
    Location
    Australia
    Posts
    108

    Re: VBA Compile Syntax Error when trying to introduce variables

    Thanks JosephP! It works like a Charm! Issue marked as resolved!

    Regards,
    Nironto

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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