Hi MrIfOnly,
Welcome to ExcelFox

I think there are probably many good reasons ( other than the less relevant these days of “using Variant data type does consume more resources” ) to be careful with your Declaring ( Diming ) of variables. Some of which I know about.


Anyway, to answer your specific question. I think this is the answer is fairly straight forward :
The Input Box displays a prompt in a dialog box, waits for the user to input text or click a button, and then returns a String containing the contents of the text box. (If the user clicks Cancel, a zero-length String is returned. )

VBA does not have to guess in this case. It is given a String


_.....................

Alan

This is an example of where using a Variant can catch you out


You probably know that you can refer to many things in VBA through their Item Number. In addition for many things you can also refer to them by their item String Number.

For example , form here:
https://www.excelforum.com/excel-pro...ml#post4183530

As example a Worksheet can be referred to in ways such as these

Worksheets.Item(1)
Worksheets.Item(“Sheet1”)


( As Item is usually the default Property in VBA , then you can do this_..
Worksheets(1)
Worksheets(“Sheet1”)
_.. In my opinion that is also a bit of a bad habit as you are relying on VBA to guess. I think only VBA has some of these defaults, so if you get in the habit you might do it in other languages that do not have it as the default
)


The danger is that you can , and people sometimes do , use a number as a String name, like

Worksheets.Item(“128746712”)

That is no problem when hard coding as in the last line

But consider that you are using a variable, and are careless in how you Declare it, that is to say it is a Variant, containing the ____ 128746712
Say a Variant type variable, var, has 128746712 in it , and you do this

Worksheets.Item(var)

Depending on exactly how / where / when you “filled” that variable, var, it may be a Variant holding a String , or a Variant holding a Number.
If it is holding a String, then no problem. If it is holding a number, then you will effectively have

Worksheets.Item(128746712)

You can probably guess what happens here: VBA tries to reference the 128746712 th Worksheet !!!

To be on the safe side, ( “Belt an Braces” ), I always do like this

Worksheets.Item("" & var & "")
or this
Worksheets.Item("" & var)

The above two concatenate a String or Strings ( all be it of zero length ) with a String or a number. The end result is a String

_................


You probably know what Rick is demonstrating: In String building you can use a & or a +
If the variables are strings you get for S1 + S2 like
S1 & S2, __ - the two numbers ( actually string characters ) are physically “stuck” together side by side

If the variables are numbers you get for S1 + S2 like
S1 + S2 __ - the numbers are added mathematically



Alan


P:S. Lööking at snb's response made me think again about an age old problem of trying to Put into a VBA String Variable a text which includes itself a quote or two...
I know how to do it, but often, like now puzzle as to why.
To get for example displayed this_..
____how to get “from” the current cell to the other referenced cell
:.. the string I type in VBA code is
__= "how to get "“from"” the current cell to the other referenced cell"
What I am thinking is that we might be tricking VBA a bit here. - We see a correct syntaxly pair - a starting " and finishing “
So we have two Strings
__= "how to get "
__= ” the current cell to the other referenced cell"
In between we have something that again appears syntax valid to build into a String, but somehow is not. VBA is somehow confused and just talks it as “from” and puts exactly that between the other two Strings...