Benudharc
Benudharc

Reputation: 17

Vba concatenation

I am trying to concatenate this but it is not working. I have initialized my array in this way (Dim Myarray(1 To 2) As String.)

I dont know weather Myarray has been initialized or not after passing it as string . i tried debugging the code with (debug.print) but i was able to print only one by one values .

But when i print (myarray) code mismatch error is coming.

Debug.Print Myarray

I need both the values in one variable myarray . so that i can pass both the values of the array variable in a single URl and get the expected result

    Myarray(1) = 141599734375#
    Myarray(2) = 161631397677#
    'Debug.Print Myarray(1)
     With Sheet1.QueryTables.Add(Connection:= _
        "URL;http://www.ebay.in/itm/" + "Myarray)", _
        Destination:=Sheet1.Range("$A$9"))

I have initialized my array in this way (Dim Myarray(1 To 2) As String.) I dont know weather Myarray has been initialized or not after passing it as string . Please look into the above code and help me resolving this issue. I am new to VBA,Please help me solving this issue.

Upvotes: 0

Views: 809

Answers (2)

genespos
genespos

Reputation: 3311

If you need to use both numbers in the array (one after another) this can solve:

 With Sheet1.QueryTables.Add(Connection:= _
    "URL;http://www.ebay.in/itm/" & Myarray(0) & Myarray(1)), _
    Destination:=Sheet1.Range("$A$9"))

If you need a separetor between the two values you can add it this way:

 With Sheet1.QueryTables.Add(Connection:= _
    "URL;http://www.ebay.in/itm/" & Myarray(0) & "separator" & Myarray(1)), _
    Destination:=Sheet1.Range("$A$9"))

Upvotes: 0

Tipsy
Tipsy

Reputation: 68

You might want to try this.

Dim Myarray(0 To 1) As String

Myarray(0) = "141599734375"
Myarray(1) = "161631397677"

Dim myNewArray As String

myNewArray = Join(myArray, ", ")

Debug.WriteLine (myNewArray)

For your reference: http://www.globaliconnect.com/excel/index.php?option=com_content&view=article&id=270:excel-vba-string-functions-split-join-concatenate&catid=79&Itemid=475

Upvotes: 1

Related Questions