Home > OS >  I have problem Concatenate with "&" and two value VBA excel
I have problem Concatenate with "&" and two value VBA excel

Time:06-02

I have problem with this code, it's showing me an error , why is this wrong?

dim aData   as Variant
dim TBNumV  as Long
eRows       as Long
aData.value="433-333-"
TBNumV.value=0635
eRows=15
Range(eRows, 2).Value = aData.Value & TBNumV.Value

CodePudding user response:

If you write something with a dot, you are referring to a method or property of an object. A Range is an object and has (among others) a property Value (is has also other properties like Font, Address, Interior...).

A simple variable like a Long is not an object in VBA, it has no properties, you simply write TBNumV = 0635.

A special case it the Variant, a Variant can be anything, depending on how you use it. You could assign an object to a variant variable (but you don't do in your code). You use it as a simple variable and want to assign a string to it: aData = "433-333-". You could consider to declare aData as String, use Variant only if you really need to.

Then you have a syntax error declaring eRows, the Dim-statement is missing.

And your syntax for Range is wrong. Either write Range("B" & eRows) or you can use Cells(eRows, 2).

Dim aData   As Variant
Dim TBNumV  As Long
Dim eRows       As Long
aData = "433-333-"
TBNumV = 635
eRows = 15
Cells(eRows, 2).Value = aData & TBNumV
  •  Tags:  
  • vba
  • Related