StuartJones
Programmer
Hi,
I'm having a bit more trouble now.
This code was working about an hour ago, and now it isn't. I didn't change anything (simply closed the workbook and then re-opened it).
I keep getting errors on the Worksheets(2).Columns("A:A").Select command
TIA - Stuart
[tt]
Private Sub CommandButton1_Click()
Dim csv_file As String
Dim file_number As Integer
Dim i As Integer
Dim temp_var As String
csv_file = InputBox("Enter the full path to the file (e.g., c:\dir_name\import.csv)", "Filename")
If Not csv_file = "" Then
file_number = FreeFile(1)
Open csv_file For Input As #file_number
i = 1
Do
Line Input #file_number, temp_var
Worksheets(2).Range("A" & i).Value = temp_var
i = i + 1
Loop Until (EOF(file_number))
Close
Worksheets(2).Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
Array(7, 1), Array(8, 1), Array(9, 1)), TrailingMinusNumbers:=True
End If
End Sub
[/tt]
I'm having a bit more trouble now.
This code was working about an hour ago, and now it isn't. I didn't change anything (simply closed the workbook and then re-opened it).
I keep getting errors on the Worksheets(2).Columns("A:A").Select command
TIA - Stuart
[tt]
Private Sub CommandButton1_Click()
Dim csv_file As String
Dim file_number As Integer
Dim i As Integer
Dim temp_var As String
csv_file = InputBox("Enter the full path to the file (e.g., c:\dir_name\import.csv)", "Filename")
If Not csv_file = "" Then
file_number = FreeFile(1)
Open csv_file For Input As #file_number
i = 1
Do
Line Input #file_number, temp_var
Worksheets(2).Range("A" & i).Value = temp_var
i = i + 1
Loop Until (EOF(file_number))
Close
Worksheets(2).Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
Array(7, 1), Array(8, 1), Array(9, 1)), TrailingMinusNumbers:=True
End If
End Sub
[/tt]