Skip to content

Instantly share code, notes, and snippets.

@jakelosh
Created January 9, 2015 19:34
Show Gist options
  • Save jakelosh/d3534346093083067d74 to your computer and use it in GitHub Desktop.
Save jakelosh/d3534346093083067d74 to your computer and use it in GitHub Desktop.
I often have a need to query my company's proprietary database using securities identifiers I get from a spreadsheet. I wrote this script to help me do that more efficiently. I store it in my personal workbook so I can use it anytime I open Excel. The script takes any selected range (contiguous or not) and puts single quotes around the values in…
Public Sub AddSingleQuotes()
Dim rng as Range
Set rng = Selection
Dim cell as Range
Dim booFirst as Boolean
booFirst = True
With rng
For Each cell in rng
If booFirst = True Then
cell.Value = "''" & cell.Value & "'"
booFirst = False
Else
cell.Value = ",'" & cell.Value & "'"
End if
Next cell
End With
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment