Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel - Select all columns error

Status
Not open for further replies.

StuartJones

Programmer
Jul 10, 2002
30
0
0
GB
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]
 
Hi,

Looks like you are CLOSING something just before you want to make that Select. Worksheet(2) has to be ACTIVE before you can Select anything on it.

I try to avoid activating and selecting.

faq707-4105 How Can I Make My Code Run Faster?

:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks Skip,

As I said in my other question today, I'm not too well-up on VBA, so I'm kinda throwing things from the on-line help together and hoping it sticks :)


Cheers for your help - I got the code working again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top