View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Excel Curious Excel Curious is offline
external usenet poster
 
Posts: 23
Default Vba code cannot select text pasted from .txt file

There is no misspelling and I have tried using Range in place of Columns. The
exact same code works on other worksheets that do not have the pasted text.
I'm using Select because the next line of the code runs a find on the
selection.

Is it possible the text from the .txt file is somehow corrupt (although it
looks fine)? And if so is there a way to un-corrupt it?

"B Lynn B" wrote:

On the chance that it's not a mis-spelling or syntax error, you could simply
try Range("A:A").Select instead of Columns("A:A").Select.

Also just as food for thought/learning... it's generally not necessary to
"select" objects in order to manipulate them with VBA. e.g.:

Range("A:A").Copy

is the same as

Range("A:A").Select
Selection.Copy




"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.