Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Help for Macro: Finding last cell and selecting it

Hi

I need help for a macro i am writing.

I need it to find the last used cell and select everything from e.g.
A2 to the last used cell. I can do the functions seperately but
cannot combine it.

Can anyone help? If you can, here's thanks to you

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Help for Macro: Finding last cell and selecting it

Think i got it with this code:


ActiveSheet.Range("a1:" & ActiveSheet.Range("a1"). _
End(xlDown).Address).Select

On 28 Jan., 19:27, wrote:
Hi

I need help for a macro i am writing.

I need it to find the last used cell and select everything from e.g.
A2 to the last used cell. I can do the functions seperately but
cannot combine it.

Can anyone help? If you can, here's thanks to you


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 196
Default Help for Macro: Finding last cell and selecting it

Just be a bit wary that if you have a blank cell in the A column
before your last data row, then you will end up with the wrong range
(as xlDown will stop before the blank cell). To avoid this, you can
go the other way:

Set myRange = Range("A1:A" & Cells(Application.Rows.Count,
1).End(xlUp).Row)

Hope this helps!

Richard

On 28 Jan, 18:34, wrote:
Think i got it with this code:

ActiveSheet.Range("a1:" & ActiveSheet.Range("a1"). _
End(xlDown).Address).Select

On 28 Jan., 19:27, wrote:

Hi


I need help for a macro i am writing.


I need it to find the last used cell and select everything from e.g.
A2 to the last used cell. I can do the functions seperately but
cannot combine it.


Can anyone help? If you can, here's thanks to you


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Help for Macro: Finding last cell and selecting it

Thanks

Does this mean that my macro should be:

Sub Test()


ActiveSheet.Range("a2:" & ActiveSheet.Range("e8"). _
End(xlToRight).Address).Select

Set myRange = Range("A1:A" & Cells(Application.Rows.Count,
1).End(xlUp).Row)


End Sub

Because if i only enter:

Set myRange = Range("A1:A" & Cells(Application.Rows.Count,
1).End(xlUp).Row)


i get an error message.

On 28 Jan., 19:40, "RichardSchollar"
wrote:
Just be a bit wary that if you have a blank cell in the A column
before your last data row, then you will end up with the wrong range
(as xlDown will stop before the blank cell). To avoid this, you can
go the other way:

Set myRange = Range("A1:A" & Cells(Application.Rows.Count,
1).End(xlUp).Row)

Hope this helps!

Richard

On 28 Jan, 18:34, wrote:

Think i got it with this code:


ActiveSheet.Range("a1:" & ActiveSheet.Range("a1"). _
End(xlDown).Address).Select


On 28 Jan., 19:27, wrote:


Hi


I need help for a macro i am writing.


I need it to find the last used cell and select everything from e.g.
A2 to the last used cell. I can do the functions seperately but
cannot combine it.


Can anyone help? If you can, here's thanks to you


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 196
Default Help for Macro: Finding last cell and selecting it

Hi Kasper

You shouldn't need anything else - the code should be fully functional
on its own.

What error do you receive?

By the way (and I don't think this is a problem for you) the way it is
written, the range references default to the Activesheet. Should you
want to specify a range on another sheet (eg Sheet2) then you would
need to write it like:

With Sheets("Sheet2")
Set myRange = .Range("A1:A" & .Cells(Application.Rows.Count,
1).End(xlUp).Row)
End With

Note the dot (.) before both Range and Cells (after the Set
statement).

Best regards

Richard

On 28 Jan, 18:55, wrote:
Thanks

Does this mean that my macro should be:

Sub Test()

ActiveSheet.Range("a2:" & ActiveSheet.Range("e8"). _
End(xlToRight).Address).Select

Set myRange = Range("A1:A" & Cells(Application.Rows.Count,

1).End(xlUp).Row)End Sub


Because if i only enter:

Set myRange = Range("A1:A" & Cells(Application.Rows.Count,

1).End(xlUp).Row)i get an error message.


On 28 Jan., 19:40, "RichardSchollar"
wrote:



Just be a bit wary that if you have a blank cell in the A column
before your last data row, then you will end up with the wrong range
(as xlDown will stop before the blank cell). To avoid this, you can
go the other way:


Set myRange = Range("A1:A" & Cells(Application.Rows.Count,
1).End(xlUp).Row)


Hope this helps!


Richard


On 28 Jan, 18:34, wrote:


Think i got it with this code:


ActiveSheet.Range("a1:" & ActiveSheet.Range("a1"). _
End(xlDown).Address).Select


On 28 Jan., 19:27, wrote:


Hi


I need help for a macro i am writing.


I need it to find the last used cell and select everything from e.g.
A2 to the last used cell. I can do the functions seperately but
cannot combine it.


Can anyone help? If you can, here's thanks to you- Hide quoted text -- Show quoted text -


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fill a cell by selecting a value from a list yasser Excel Worksheet Functions 1 November 14th 06 06:21 PM
Enter value in cell by selecting cell. Greyson Excel Discussion (Misc queries) 2 November 2nd 06 12:01 AM
Help! I want to fill cells as a result of selecting a value from a list in another cell. Tricky Excel Worksheet Functions 6 August 11th 06 10:47 PM
Finding a minimum value and selecting the cell containing this val Kokomojo Excel Worksheet Functions 3 February 5th 06 09:33 PM
excel locks up after selecting a cell sandenscot Excel Discussion (Misc queries) 7 January 28th 05 07:27 PM


All times are GMT +1. The time now is 02:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"