Skip to content
Advertisement

VBA Function/ Code – Convert Dynamic Column of Data into Text String

I’m creating a tool where users can query an ODBC through excel. I need a function which will look at a column of item id’s which the user has pasted in and then create a text string which can be used in the Sql part of the VBA. The number of item Id’s can vary.

Using a similar function (not created by myself), I can reference one cell and insert the ‘ and , where needed but I can’t seem to get this to work for multiple cells in one column.

‘Here is the code I have used for the existing function:

If the column of data was to look like this:

test1 test2

I need the output to look like this:

in (‘test2’, ‘test1’)

Advertisement

Answer

The formula you have is incomplete, it doesn’t show the ending, but here’s a function that loops through any amount of cells and constructs a string that looks similar to what you’re looking for. You can change the prefix in the constants at the top of the formula or tinker with it to get whatever manipulations you want done.

enter image description here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement