Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Auto Add Row


Hi!
I have a named range "Eng1" (B1:B5) and if the user enters data int
all 5 cells I want the range to expand to include (insert) a new row.
want the new row to be B6. In other words I want the bottom cell i
range "Eng1" to always be blank. It will start out 5 rows deep an
expand from there (no max) There are formulas in the adjacent cell
that I want to fill down when the new row is added.

I know this is possible but I have no clue where to start.

Any help or direction would be greatly appreciated! Thanks!

--
Brian Matlac
-----------------------------------------------------------------------
Brian Matlack's Profile: http://www.excelforum.com/member.php...nfo&userid=350
View this thread: http://www.excelforum.com/showthread.php?threadid=54466

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Auto Add Row

Start with the change event

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
On Error GoTo ErrHandler
Set rng = Range("eng1")
If Not Intersect(rng, Target) Is Nothing Then
If rng.Count = Application.CountA(rng) Then
Application.EnableEvents = False
rng.Resize(rng.Rows.Count + 1, 1).Name = "eng1"
rng(rng.Count).Offset(1, 1).Resize(1, 6).FillDown
End If
End If
ErrHandler:
Application.EnableEvents = True
End Sub


If your not familiar with events, then see Chip Pearson's page providing an
overview
http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy


"Brian Matlack" wrote:


Hi!
I have a named range "Eng1" (B1:B5) and if the user enters data into
all 5 cells I want the range to expand to include (insert) a new row. I
want the new row to be B6. In other words I want the bottom cell in
range "Eng1" to always be blank. It will start out 5 rows deep and
expand from there (no max) There are formulas in the adjacent cells
that I want to fill down when the new row is added.

I know this is possible but I have no clue where to start.

Any help or direction would be greatly appreciated! Thanks!!


--
Brian Matlack
------------------------------------------------------------------------
Brian Matlack's Profile: http://www.excelforum.com/member.php...fo&userid=3508
View this thread: http://www.excelforum.com/showthread...hreadid=544668


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Auto Add Row

Hi Brian,

you can define your named range "Eng1" to be
=OFFSET($A$1,0,0,MAX(5,COUNTA(A1:A65536)+1),1)

Regards,
Ivan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Auto Add Row

sorry, you wanted b1:b5

=OFFSET($b$1,0,0,MAX(5,COUNTA($b$1:$b$65536)+1),1)

regards,
Ivan

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Auto Add Row


Tom:
The code worked fine. Thanks!! However! I failed to mention that
wanted to apply this code to a total of 35 different ranges in thi
worksheet. I can repeat the code 35 times with different range name
but I suspect there is a loop that will do it more efficiently. If yo
or anyone has time I would be interested to know how to do it.

Ivan:
I appreciate your suggestion I'll save it for future use. Thanks!

--
Brian Matlac
-----------------------------------------------------------------------
Brian Matlack's Profile: http://www.excelforum.com/member.php...nfo&userid=350
View this thread: http://www.excelforum.com/showthread.php?threadid=54466



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Auto Add Row

Hi Brian,

you can easily adapt Tom's code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
dim nName as name

On Error GoTo ErrHandler
for each nName in activeworkbook.names
Set rng = Range(nName)
If Not Intersect(rng, Target) Is Nothing Then
If rng.Count = Application.CountA(rng) Then
Application.EnableEvents = False
rng.Resize(rng.Rows.Count + 1, 1).Name = nName.name
rng(rng.Count).Offset(1, 1).Resize(1, 6).FillDown
End If
End If
next nName
ErrHandler:
Application.EnableEvents = True
End Sub

Regards,
Ivan

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Auto Add Row


Ivan:
Thanks!! That worked great. I'm pretty much a rookie at this stuff a
you can tell. I do appreciate all the help from everyone on the Forum
It's a great tool with some realy great people involved.

Sorry for the editorial!! One last (silly) question.

How can I make the active cell (goto) the last cell in a named rang
ie. Range "eng1" is A1:A9 and I want the active cell to be A9 but i
the range definition changes to A1:A12 I now want to go to A12. What i
the range is defined as A1:D12 is there a way to get to A12 or B12 ect.

Thanks again for all the help!

--
Brian Matlac
-----------------------------------------------------------------------
Brian Matlack's Profile: http://www.excelforum.com/member.php...nfo&userid=350
View this thread: http://www.excelforum.com/showthread.php?threadid=54466

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Auto Add Row

Hi Brian,

added one row of code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
dim nName as name

On Error GoTo ErrHandler
for each nName in activeworkbook.names
Set rng = Range(nName)
If Not Intersect(rng, Target) Is Nothing Then
If rng.Count = Application.CountA(rng) Then
Application.EnableEvents = False
rng.Resize(rng.Rows.Count + 1, 1).Name = nName.name
rng(rng.Count).Offset(1, 1).Resize(1, 6).FillDown
rng.cells(rng.rows.count,1).activate ' added
End If
End If
next nName
ErrHandler:
Application.EnableEvents = True
End Sub

Regards,
Ivan

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
Excel 2007 auto-recovery / auto-save? gpurdue Setting up and Configuration of Excel 0 May 23rd 08 10:19 PM
Auto-populate, Auto-copy or Auto-fill? Jay S. Excel Worksheet Functions 4 August 10th 07 09:04 PM
How to AUTO SAVE as opposed to turning on auto recovery: EXCEL T-mo Excel Discussion (Misc queries) 1 January 12th 06 10:16 PM
Auto Excel workbook close: save= false during an auto subroutine tomwashere2 Excel Programming 10 June 16th 05 06:23 AM
excel links update not working in auto, calculations in auto Mikey Boy Excel Worksheet Functions 0 December 7th 04 11:53 PM


All times are GMT +1. The time now is 06:48 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"