Taking data from a worksheet

T

Tangier

Hi,

I want to put a range of data into a worksheet. I want the user to
input the values, integers (Child IDs) into the F column.

From the F column, I want my subroutine to take these values, turn
them into a comma separated list string, and put it into another
string so it will look like this:

SQL String = " WHERE ChildID IN ( " & Comma spearated list string &
" ) "

My question is, how do I create a comma separated list string with
dynamic ranges?
 
A

AltaEgo

This should get you started:

It assumes column F contains no data below the list and no gaps in the list.
You may need to make sure it references the right worksheet before it runs

'*********************

Function strSQL()

Dim c, tmp

Range("f65536").Select
Selection.End(xlUp).Select
Range(Selection, Selection.End(xlUp)).Select

For Each c In Selection
If tmp & "" = "" Then
tmp = " WHERE ChildID IN (" & c.Value
Else
tmp = tmp & "," & c.Value
End If
Next c

tmp = tmp & ")"
strSQL = tmp

End Function

'*********************

Depending on your project, you may need to activate the correct workbook
and/or worksheet containing the data first.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top