Skip to content

Instantly share code, notes, and snippets.

@teramako
Created June 27, 2016 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teramako/4d68520943000ddcb1c238aa23187299 to your computer and use it in GitHub Desktop.
Save teramako/4d68520943000ddcb1c238aa23187299 to your computer and use it in GitHub Desktop.
Excel VBAの標準モジュールに追加してる関数
' ="SELECT ..... FROM ... WHERE column_A in ("&join(A1:A10,",","'")&")" などと式に使うことを想定
' SQLインジェクション可能だが知らん。
Function join(r As Range, Optional delimiter As String = ",", Optional wrap As String = "'") As String
Dim i As Integer
Dim result = As String
result = wrap & r.Cells(1, 1).Value & wrap
For i = 2 To r.rows.Count
result = result & delimiter & wrap & r.Cells(i, 1).Value & wrap
Next i
join = result
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment