Created
January 9, 2015 19:34
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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