ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   New to excel macros need help with selecting ranges (https://www.excelbanter.com/excel-programming/429097-new-excel-macros-need-help-selecting-ranges.html)

[email protected]

New to excel macros need help with selecting ranges
 
I have need a macro that will select a range in a column and copy
data.
In one spreadsheet the column range maybe N2 - N15
the next time the column range maybe N2 - N250

How can I code it to select N2 - last cell in column so I don't have
to change macro each time for each spreadsheet.

Thank you

Terrie

Mike H

New to excel macros need help with selecting ranges
 
Hi,

Try this

lastrow = Cells(Rows.Count, "N").End(xlUp).Row
Range("N2:N" & lastrow).Select

Mike

" wrote:

I have need a macro that will select a range in a column and copy
data.
In one spreadsheet the column range maybe N2 - N15
the next time the column range maybe N2 - N250

How can I code it to select N2 - last cell in column so I don't have
to change macro each time for each spreadsheet.

Thank you

Terrie


Don Guillett

New to excel macros need help with selecting ranges
 
How about a nice one liner broken up to account for possible word wrap. NO
selections

Sub copyrng()
Cells(2, 4).Resize(Cells(Rows.Count, 4). _
End(xlUp).Row - 1).Copy range("z5")
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

wrote in message
...
I have need a macro that will select a range in a column and copy
data.
In one spreadsheet the column range maybe N2 - N15
the next time the column range maybe N2 - N250

How can I code it to select N2 - last cell in column so I don't have
to change macro each time for each spreadsheet.

Thank you

Terrie



[email protected]

New to excel macros need help with selecting ranges
 
On May 28, 2:41*pm, "Don Guillett" wrote:
How about a nice one liner broken up to account for possible word wrap. NO
selections

Sub copyrng()
Cells(2, 4).Resize(Cells(Rows.Count, 4). _
* End(xlUp).Row - 1).Copy range("z5")
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
wrote in message

...



I have need a macro that will select a range *in a column and copy
data.
In one spreadsheet the column range maybe N2 - N15
the next time the column range maybe N2 - N250


How can I code it to select N2 - last cell in column so I don't have
to change macro each time for each spreadsheet.


Thank you


Terrie- Hide quoted text -


- Show quoted text -



Thank you all for your help. Your information pointed me in the
direction to accomplish my selection.

Don Guillett

New to excel macros need help with selecting ranges
 
Glad to help. However, it is not necessary to SELECT. Post your code for
comments.


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

wrote in message
...
On May 28, 2:41 pm, "Don Guillett" wrote:
How about a nice one liner broken up to account for possible word wrap. NO
selections

Sub copyrng()
Cells(2, 4).Resize(Cells(Rows.Count, 4). _
End(xlUp).Row - 1).Copy range("z5")
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
wrote in message

...



I have need a macro that will select a range in a column and copy
data.
In one spreadsheet the column range maybe N2 - N15
the next time the column range maybe N2 - N250


How can I code it to select N2 - last cell in column so I don't have
to change macro each time for each spreadsheet.


Thank you


Terrie- Hide quoted text -


- Show quoted text -



Thank you all for your help. Your information pointed me in the
direction to accomplish my selection.



All times are GMT +1. The time now is 06:30 PM.

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