Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save stevesohcot/4a6cb6b3fda2e565176dd0676519e619 to your computer and use it in GitHub Desktop.

Select an option

Save stevesohcot/4a6cb6b3fda2e565176dd0676519e619 to your computer and use it in GitHub Desktop.
VBA Import data single row
Public Function getSQLForSingleRow(sheet As String, rowNumber As Long) As String
' Be sure to update any formatting; ex date or number
fieldWithText = ReplaceSingleQuote(Worksheets(sheet).Range("A" & rowNumber).FormulaR1C1)
fieldWithDate = Format(Worksheets(sheet).Range("B" & rowNumber).FormulaR1C1, "mm/dd/yyyy")
fieldWithNumbers = CDbl(Nz(Worksheets(sheet).Range("C" & rowNumber).FormulaR1C1))
Dim strSQL As String
strSQL = " ("
strSQL = strSQL & " '" & fieldWithText & "',"
strSQL = strSQL & " '" & fieldWithDate & "',"
strSQL = strSQL & " " & fieldWithNumbers & "" ' no quotes because it's numeric
strSQL = strSQL & " ) "
getSQLForSingleRow = strSQL
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment