Cells.Select won't work!!!

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a workbook that contains a macro that opens a file. Then the file is
sorted the way it should. But I get an error on the Cells.Select command:
Run-time error '1004': Select method of Range class failed
Here's what my code looks like:

ActiveWorkbook.Save
Range("D4").Select
CSV = ActiveCell.Value
Windows(CSV).Activate
Cells.Select
Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Key2:=Range("A2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal

Is there a different way to select all the cells in the workbook? Does
anyone have any ideas about what I'm missing? Thanks in advance. I don't
know if it matters, but the file that is being sorted is a csv file.
 
If you want to select all the cells on a worksheet, you must firs
select the sheet.

Sheets("mysheet").Select
Cells.Select

(notice that Sheets("mysheet").Cells.Select will not work until th
sheet itself is first selected - even if it is activated)

Good luc
 
Hei Neil

You don't have to activate or select anything to sort a table. If you
explain what this
CSV = ActiveCell.Value
Windows(CSV).Activate
does, I could perhaps write you a working demo.

HTH. best wishes Harald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top