ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   selecting a row (https://www.excelbanter.com/excel-worksheet-functions/150070-selecting-row.html)

Srikanth

selecting a row
 
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

Trevor Shuttleworth

selecting a row
 
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


"srikanth" wrote in message
...
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




Srikanth

selecting a row
 
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


"Trevor Shuttleworth" wrote:

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


"srikanth" wrote in message
...
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





JLatham

selecting a row
 
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.

"srikanth" wrote:

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


"Trevor Shuttleworth" wrote:

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


"srikanth" wrote in message
...
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





Trevor Shuttleworth

selecting a row
 
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


"srikanth" wrote in message
...
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


"Trevor Shuttleworth" wrote:

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


"srikanth" wrote in message
...
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







Srikanth

selecting a row
 
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
"JLatham" wrote:

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.

"srikanth" wrote:

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


"Trevor Shuttleworth" wrote:

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


"srikanth" wrote in message
...
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




Srikanth

selecting a row
 
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




"Trevor Shuttleworth" wrote:

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


"srikanth" wrote in message
...
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


"Trevor Shuttleworth" wrote:

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


"srikanth" wrote in message
...
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








All times are GMT +1. The time now is 04:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com