Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
CM CM is offline
external usenet poster
 
Posts: 136
Default need macro for auto range name (#rows different each time)

I need a macro to name a range that will have a different number of populated
rows each time the macro is generated. Recording the keystrokes is not
successful.

I can set the range name to include enough rows to accommodate the most
possible records, however this range is being used for a data validation
drop-down list. The result with a pre-set range name produces too many blank
rows at the bottom of the list -- looks unprofessional.

Please advise,

cm
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default need macro for auto range name (#rows different each time)

Hi,

Find the last used row and then set the range

lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
ActiveSheet.Names.Add Name:="MyRange", RefersTo:=ActiveSheet.Range("A1:A" &
lastrow)

Mike

"cm" wrote:

I need a macro to name a range that will have a different number of populated
rows each time the macro is generated. Recording the keystrokes is not
successful.

I can set the range name to include enough rows to accommodate the most
possible records, however this range is being used for a data validation
drop-down list. The result with a pre-set range name produces too many blank
rows at the bottom of the list -- looks unprofessional.

Please advise,

cm

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default need macro for auto range name (#rows different each time)

Try the below. The macro will identify the last filled row in Column A and
create a named range...

Dim lngLastRow As Long
lngLastRow = Worksheets("Sheet1").Cells(Rows.Count, _
"A").End(xlUp).Row
ActiveWorkbook.Names.Add Name:="newRange", _
RefersTo:="=Sheet1!$A$1:$A$" & lngLastRow
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"cm" wrote:

I need a macro to name a range that will have a different number of populated
rows each time the macro is generated. Recording the keystrokes is not
successful.

I can set the range name to include enough rows to accommodate the most
possible records, however this range is being used for a data validation
drop-down list. The result with a pre-set range name produces too many blank
rows at the bottom of the list -- looks unprofessional.

Please advise,

cm

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default need macro for auto range name (#rows different each time)

you could use a DYNAMIC range name

in teh Insert Names window, you set the refers to box like this

=OFFSET(Sheet1!$D$9,0,0,COUNTA(Sheet1!$D:$D),1)

here, my list starts at D9
I have no other data in D so its safe to count any item as it will be in the
list
if you're sure that the list will never do beyond a certain size, you could
limit the length..
=OFFSET(Sheet1!$D$9,0,0,COUNTA(Sheet1!$D9:$D19),1)

this says from D9, oddet no rows or columns, but make it several rows and
one column




"cm" wrote:

I need a macro to name a range that will have a different number of populated
rows each time the macro is generated. Recording the keystrokes is not
successful.

I can set the range name to include enough rows to accommodate the most
possible records, however this range is being used for a data validation
drop-down list. The result with a pre-set range name produces too many blank
rows at the bottom of the list -- looks unprofessional.

Please advise,

cm

  #5   Report Post  
Posted to microsoft.public.excel.programming
CM CM is offline
external usenet poster
 
Posts: 136
Default need macro for auto range name (#rows different each time)

PERFECT! Thank you SO much.

cm


"Patrick Molloy" wrote:

you could use a DYNAMIC range name

in teh Insert Names window, you set the refers to box like this

=OFFSET(Sheet1!$D$9,0,0,COUNTA(Sheet1!$D:$D),1)

here, my list starts at D9
I have no other data in D so its safe to count any item as it will be in the
list
if you're sure that the list will never do beyond a certain size, you could
limit the length..
=OFFSET(Sheet1!$D$9,0,0,COUNTA(Sheet1!$D9:$D19),1)

this says from D9, oddet no rows or columns, but make it several rows and
one column




"cm" wrote:

I need a macro to name a range that will have a different number of populated
rows each time the macro is generated. Recording the keystrokes is not
successful.

I can set the range name to include enough rows to accommodate the most
possible records, however this range is being used for a data validation
drop-down list. The result with a pre-set range name produces too many blank
rows at the bottom of the list -- looks unprofessional.

Please advise,

cm



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default need macro for auto range name (#rows different each time)

On Thursday, September 17, 2009 at 10:43:01 AM UTC-5, Jacob Skaria wrote:
Try the below. The macro will identify the last filled row in Column A and
create a named range...

Dim lngLastRow As Long
lngLastRow = Worksheets("Sheet1").Cells(Rows.Count, _
"A").End(xlUp).Row
ActiveWorkbook.Names.Add Name:="newRange", _
RefersTo:="=Sheet1!$A$1:$A$" & lngLastRow
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"cm" wrote:

I need a macro to name a range that will have a different number of populated
rows each time the macro is generated. Recording the keystrokes is not
successful.

I can set the range name to include enough rows to accommodate the most
possible records, however this range is being used for a data validation
drop-down list. The result with a pre-set range name produces too many blank
rows at the bottom of the list -- looks unprofessional.

Please advise,

cm


you are my hero! worked perfectly!!!
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
Auto-Hide Rows Macro txtstorer Excel Worksheet Functions 1 August 20th 08 08:54 PM
Macro for auto date/time stamp Bob Excel Programming 2 August 10th 06 03:25 AM
Auto delete rows within a specified range [email protected] Excel Programming 2 June 14th 06 03:30 PM
Auto Filter Delete Rows by Criteria Doesn't Work Range To Complicated robertjtucker[_8_] Excel Programming 1 September 29th 05 05:47 PM
time and auto macro run by setting time ddiicc Excel Programming 1 September 29th 05 05:32 AM


All times are GMT +1. The time now is 09:43 AM.

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

About Us

"It's about Microsoft Excel"