+ Reply to Thread
Results 1 to 5 of 5

sTemp = sTemp

  1. #1
    Registered User
    Join Date
    08-27-2021
    Location
    Gering, Nebraska
    MS-Off Ver
    2016
    Posts
    2

    Question sTemp = sTemp

    I am brand new to VBA. I need to understand what sTemp = sTemp does (with additional code) when it follow the initial sTemp = (additional code).

  2. #2
    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
    44,299

    Re: sTemp = sTemp

    Difficult to be precise without the context but, if sTemp is a range variable, and the range contains a formula, it would change the formula to its value.
    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


  3. #3
    Registered User
    Join Date
    08-27-2021
    Location
    Gering, Nebraska
    MS-Off Ver
    2016
    Posts
    2

    Re: sTemp = sTemp

    Two lines of code are: sTemp = "J + 20 = " & J & vbCrLf, sTemp = sTemp & "K + 20 = " & K I am very, very new. Would you explain this in simple English, please (sorry).

  4. #4
    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
    44,299

    Re: sTemp = sTemp

    Ok. Is this homework?

    Please Login or Register  to view this content.
    First, the ampersand (&) is used to concatenate, or join two strings together. Second, vbCrLf is a VBA constant for a carriage return, line feed … basically a new line. J and K within the double quotes are text. J and K outside the double quotes are variables.

    The two lines are building a string with a new line character in the middle, most likely to be displayed in a MsgBox.

    After the first line, the string variable sTemp would contain the text "J + 20 = " followed by whatever value is held in the variable J followed by the new line character.

    When you then say sTemp = sTemp & other stuff, it is just saying "replace the value currently held in sTemp with that value AND whatever is after the ampersand."

    So it would end up as the text "J + 20 = " followed by whatever value is held in the variable J followed by the new line character followed by the text "K + 20 = " followed by whatever value is held in the variable K.

    Let’s say you have two variables, J and K, and those variables had, say, 4 and 6 in them respectively.

    If the code looked like this:

    Please Login or Register  to view this content.

  5. #5
    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
    44,299

    Re: sTemp = sTemp

    Thanks for the rep.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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] VBA / STEMP Question
    By carl in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-22-2005, 08:05 PM

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