Array formating

Shogun

New Member
Joined
Sep 1, 2010
Messages
49
Im having trouble with part of this. I need to take values from column A and put them into an array that will be passed to another program. But the catch is when its passed i need the values to be with special formating. The range of Values are dynamic and can be anywhere from 3 to a couple thousand.

So after i have the values i need to send them back like this: ('value1','value2','value3')

Is this easy to do or am i stuck?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi

Maybe this example helps?

Code:
Sub Test()
Dim sArray(1 To 4) As String
 
sArray(1) = "Test1"
sArray(2) = "Test2"
sArray(3) = "Test3"
sArray(4) = "Test4"
 
MsgBox "('" & Join(sArray, "','") & "')"
End Sub
 
Upvote 0
This is working the way i need but now how can i make array dynamic from a range that will still work with a join?

Code:
Dim sArray As Variant
LastRow = Range("O" & Rows.Count).End(xlUp).ROW
sArray = Range("O1:O" & LastRow).Value
MsgBox "('" & Join(sArray, "','") & "')"
 
Upvote 0
Hi

Try:

Code:
Sub Test()
Dim r As Range
 
Set r = Range("O1", Range("O" & Rows.Count).End(xlUp))
MsgBox "('" & Join(Application.Transpose(r), "','") & "')"
End Sub
 
Upvote 0
O so close this works the way i want it to but when i use in dosent include the end ")" for some reason.

Code:
Dim objOptTab As Object
Dim r As Range

objOptTab.FreeTable
Set r = Range("O1", Range("O" & Rows.Count).End(xlUp))
 
objOptTab.Rows.Add
objOptTab(objOptTab.RowCount, "TEXT") = "MATNR IN ('" & Join(Application.Transpose(r), "','") & "')"

For some reason its only showing as : Data(1,1) : "MATNR IN ('Value1','Value2','Value3'" : Variant/String
 
Upvote 0
Sorry, cannot help you there. The difference I see between your code and the one I posted is that you are using the object objOptTab, and I don't know that object.
 
Upvote 0
I figured it out I needed to pass the join to a variant and then call that in the objects line. But it was all a waste there is a character limit so I had to switch to a loop thru cells one at a time instead of writing all in to one long join string. But thanks for the help.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,766
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top