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).
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).
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
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).
Ok. Is this homework?
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.Please Login or Register to view this content.
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.
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks