+ Reply to Thread
Results 1 to 4 of 4

VBA question

  1. #1
    Registered User
    Join Date
    03-01-2018
    Location
    India
    MS-Off Ver
    2010
    Posts
    33

    VBA question

    Hello,

    First, sorry to post this basic question. I'm not a programmer, I'm just understanding the code one by one and working.

    X1$ = "&LOG Part: " & """" + SD$ + .Cells(R, 1) + ".prt" & """"
    Print #1, X1$

    The above code prints only when string is entered. If it is a pure number, I get debug error. I see dollar stands for string data type. But I don't know how to fix this. Can you please tell me how to modify this code so it accepts both string and numerical data type.

    Thank you in advance.

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,878

    Re: VBA question

    Try using & for the concatenation rather than +

  3. #3
    Registered User
    Join Date
    03-01-2018
    Location
    India
    MS-Off Ver
    2010
    Posts
    33

    Re: VBA question

    Thank you very much for your quick response. It works. If you don't mind, what is the difference between using & and + in this case?

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,878

    Re: VBA question

    & can only be used for strings.
    + is an arithmetic operator which can also be used to concatenate strings.

    If your cell contains a number and you use +, it'll try to add it numerically which is incompatible with your string variable.

+ 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] Mathematical question or excel question? Multiple several numbers in a row.
    By douglascaixeta in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 08-22-2015, 05:48 PM
  2. [SOLVED] Objective Question: High light the right answer with green before next question.
    By ebin charles in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-25-2015, 12:38 PM
  3. database question, excel data sorting question
    By weblisterltd.com in forum Excel General
    Replies: 1
    Last Post: 12-17-2014, 01:35 PM
  4. code to progressively go throughly question based on answer to first question
    By Ishwarind in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-08-2014, 06:48 AM
  5. [SOLVED] Question regarding conditional format question that covers two range criteria
    By lilsnoop in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-06-2013, 12:32 PM
  6. Replies: 3
    Last Post: 06-17-2011, 08:09 AM
  7. Two question, numeric code question and subtraction of two columns?
    By mgsweden78 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-18-2008, 02:50 AM

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