selecting a row

S

srikanth

Hi,
I have loaded a text file with delimiters in excel.. It consists of three
columns.. i would like to copy only the third column until the last cell that
contains the data.. but my code is not working correctly.. it is selecting
the entire sheet which contains data.. i have used the belw code.. pls advise
me of a better code..

Range("C1").Select
Range("C1", Selection.End(xlDown)).Select

Thanks,
srikanth
 
T

Trevor Shuttleworth

One way:

Range("C1:C" & Range("C1").End(xlDown).Row).Select

or

Range("C1:C" & Range("C65536").End(xlUp).Row).Select if there are gaps in
Column C

Is your data actually in three columns or is it in column A and just looks
as though it's across A to C?


Regards

Trevor
 
S

srikanth

Thanks for your reply..
The data is in separate columns.. A, B and C..
If i execute the below command it gives a n error..

"Select method of Range class failed"

thanks,
srikanth
 
J

JLatham

Try this line of code for your selection:

Range("C1:" & Range("C" & Rows.Count).End(xlUp).Address).Select

It does work - I've tested it. It will even work if C is empty - although
all that will be selected is C1.
 
T

Trevor Shuttleworth

Both suggestions work for me.

If the column is empty, the entire column will be selected.

In fact, your original code worked for me.


Regards

Trevor
 
S

srikanth

Hi,

Thanks a lot for your reply..
The code you have provided working fine in another same project, but the
case in what i am doing is, i uploaded a txt file with delimiters.. so after
uploading entire rows and colums containg the data is selected by default..

I beleive there is some problem in code in loading the text file.. but it
works fine.. hereis the code below.. pls update of any changes.. thanks ag
ain.

Workbooks.OpenText FileName:=FileToOpen _
, Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited,
Other:=True, OtherChar:= _
"|"

FileToOpen contains the file name..
thanks,
srikanth
 
S

srikanth

Hi,

Thanks a lot for your reply..
The code you have provided working fine in another same project, but the
case in what i am doing is, i uploaded a txt file with delimiters.. so after
uploading entire rows and colums containg the data is selected by default..

I beleive there is some problem in code in loading the text file.. but it
works fine.. hereis the code below.. pls update of any changes.. thanks ag
ain.

Workbooks.OpenText FileName:=FileToOpen _
, Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited,
Other:=True, OtherChar:= _
"|"

FileToOpen contains the file name..
thanks,
srikanth
 
Top