I have a User that receives a *.CSV file daily. When the file is opened (in Excel) some of the values become invalid. There are alpha values in a numeric field (ie. 0907C). I wrote the code below to change all the values in that column to string/text but it is not working. The original format was general for that field.
Code:
<html>
Sub Main_Processing()
Dim LastRow As Integer
Dim r As Variant
Dim n As Variant
Dim IntStr As String
'Pull in latest Nissan Detailed Grounding Report (File)
'Insure all Buyer_NNA & Grounding_Dealer_NNA entries are Text, this will reduce errors during
'Access Import
On Error GoTo MP_Error
ChDir "C:\"
Workbooks.Open Filename:="C:\RPMTbls\Nissan Detailed .xls"
'MyString = CStr(MyDouble)
Range("A1:A1").Select
'Determine last/Total Row - If there are empty cells in row D this will not work!!!!!!!!!
LastRow = ActiveSheet.UsedRange.Rows.Count
r = LastRow
n = 16
If Cells(1, "C") <> "GROUNDING_DEALER_NNA" Then
Exit Sub
End If
If Cells(1, "P") <> "BUYER_NNA" Then
exit sub
End If
For r = 2 To LastRow Step 1
IntStr = CStr(Cells(r, "P"))
Cells(r, n) = IntStr
Next r
Application.Quit
MP_Error:
If Err.Number = 1004 Or Err.Number = 440 Then
MsgBox Err.Number & " - " & Err.Description
MsgBox "No File exist with todays date, Excel file converstion will be bypassed"
Exit Sub
End If
MsgBox Err.Number & " - " & Err.Description
End Sub
</html>