Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / General Excel Questions / March 2008

Tip: Looking for answers? Try searching our database.

Function to insert rows on a change in a cell

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Subhash - 19 Mar 2008 01:52 GMT
Is it possible to automatically insert a blank row after a change in a cell
value
Pete_UK - 19 Mar 2008 02:17 GMT
Not using a function or a formula. You can only do that with an event macro.

Pete

> Is it possible to automatically insert a blank row after a change in a
> cell
> value
Subhash - 19 Mar 2008 02:34 GMT
Thanks Pete

What is an event macro ?

> Not using a function or a formula. You can only do that with an event macro.
>
[quoted text clipped - 3 lines]
> > cell
> > value
Gord Dibben - 19 Mar 2008 05:35 GMT
See Chip Pearson's site for more on event macros.

http://www.cpearson.com/excel/Events.aspx

This would be an example of event code....................

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim num As Integer
num = 1
  On Error GoTo stoppit
  If Intersect(Target, Me.Range("A1")) Is Nothing Then Exit Sub
  Target.Offset(1, 0).Resize(num).EntireRow.Insert
stoppit:
End Sub

When you manually change the data in A1, you will insert a blank row below that.

Right-click on the worksheet tab and "View Code"  Copy/paste into that sheet
module.

Alt + q to return to the Excel worksheet window.

BUT...................if your question was to insert a row at every change in
value down a column.

i.e.   column A has values of

abc
abc
abc
def
def
def
ghi
ghi
ghi

You want to insert a row at each change you would use a regular macro.

Sub InsertRow_At_Change()
'Sandy Mann July 1st, 2007
   Dim LastRow As Long
   Dim X As Long
   LastRow = Cells(Rows.Count, 1).End(xlUp).Row
   Application.ScreenUpdating = False
   For X = LastRow To 3 Step -1
       If Cells(X, 1).Value <> Cells(X - 1, 1).Value Then
           If Cells(X, 1).Value <> "" Then
               If Cells(X - 1, 1).Value <> "" Then
                   Cells(X, 1).EntireRow.Insert Shift:=xlDown
               End If
           End If
       End If
   Next X
   Application.ScreenUpdating = True
End Sub

Gord Dibben  MS Excel MVP

>Thanks Pete
>
[quoted text clipped - 7 lines]
>> > cell
>> > value
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.