I am trying to import an Excel spreadsheet. The fields in the
spreadsheet include a 6-digit code, some with leading zeros. These
cells are formatted as text. In the Access import wizard, the data type
in the field options is grayed out and it is importing the field as a
double. Is there any way to control the format on the import?
If you prefix the values in the Excel cells with an apostrophe ', it
forces them to be treated as text. These Excel VBA functions may help:
Sub AddApostrophesNumericToSelection()
'adds apostrophes to numeric values only
Dim C As Excel.Range
For Each C In
Application.Selection.SpecialCells(xlCellTypeConstants).Cells
If IsNumeric(C.Formula) Then
C.Formula = "'" & C.Formula
End If
Next
End Sub
Sub AddApostrophesAllToSelection()
Dim C As Excel.Range
With ActiveWorkbook.ActiveSheet
For Each C In Intersect(Selection,
..UsedRange).SpecialCells(xlCellTypeConstants).Cells
C.Formula = "'" & C.Formula
Next
End With
End Sub
Sub AddApostrophesAllToColumn( _
ByVal TheColumn As Long _
)
Dim C As Excel.Range
With ActiveWorkbook.ActiveSheet
For Each C In Intersect(.Columns(TheColumn), _
.UsedRange).SpecialCells(xlCellTypeConstants).Cells
C.Formula = "'" & C.Formula
Next
End With
End Sub
Sub RemoveApostrophes()
Dim C As Excel.Range
For Each C In Application.Selection.Cells
C.Formula = C.Formula
Next
End Sub