View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Vba code cannot select text pasted from .txt file

You didn't paste the procedure name that holds this code--or where that
procedure is located.

If the code is in a General module, then I would expect it to work ok.

But if the code is in a worksheet module (some sort of event/control
procedure???), then it won't.

If the code is in a General module, then the unqualified range (Columns() would
refer to the active sheet.

If the code is in the worksheet, then the unqualified range belongs to the
worksheet that owns the code--and I bet that's not Sheet5.

Try:

Worksheets("Sheet5").select
Worksheets("Sheet5").columns("A:A").select

or (less typing):
with worksheets("Sheet5")
.select
.columns("A:A").select
End with

But even better would be to drop the selection stuff and just work on it
directly.

with worksheets("Sheet5")
.columns("A:A").numberformat = "General" 'for instance
...
end with

Excel Curious wrote:

The data I'm working with is from a .txt file which was created by exporting
a .pdf to a text file.

I copy all of the text from the .txt file and paste it into a column in Excel.

When trying to reference any column, row, or range on the sheet with the
pasted text, I get the following error: Run-time error '1004':
Application-defined or object-defined error.

Sample code:
Sheets("Sheet5").Select ' <this works fine
Columns("A:A").Select ' <this gets the error

I've tried pasting the text with other paste special options. I've tried
referencing the text on another sheet and running the code off of it. I've
tried using the Text formula to reformat the text. But, none of this seems to
be working. I cannot select any area on a sheet that has or references this
text... and therefore cannot use it in my code.


--

Dave Peterson