View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz[_2_] JLGWhiz[_2_] is offline
external usenet poster
 
Posts: 1,565
Default IF statement inserting new rows

Yes, I noticed that it was vague, but thought I would throw a template out
for the OP to work from. If it does not do what they want, they can make
remarks and we can fix it. Some people just cannot put their requirements
into a concise statement.


"Rick Rothstein" wrote in message
...
I'm not completely convinced this is what the OP is after; but, in case it
is, I have a couple of comments on your code. First, I think it would be a
good idea to check if the Target is a single cell or not (otherwise
multiple cell actions, delete perhaps, will affect unintended cells). You
need to offset the target by one row otherwise the inserted cells will go
on top, not below, it. A personal preference of mine is to minimize the
checking for the target's applicability. Since the OP wants just Column A
to be checked, there is no need to intersect the column with the target
for that check... just check the target's column. Here is how I would do
your code...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 7 And Target.Count = 1 Then
Application.EnableEvents = False
Target.Offset(1).EntireRow.Resize(3).Insert xlDown
Application.EnableEvents = True
End If
End Sub

--
Rick (MVP - Excel)


"JLGWhiz" wrote in message
...
See if this helps.

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:A")) Is Nothing Then
Application.EnableEvents = False
Target.Resize(3, 1).EntireRow.Insert
End If
Application.EnableEvents = True
End Sub


"PVANS" wrote in message
...
Good afternoon everyone

Hope someone can help me with this.

I have a worksheet that is filled rows of information about
transactions.
The column A in the worksheet is the date the transaction occured.

I would like to have a macro that notices when there is a change in
date,
and then inserts 3 rows below the final transction on the one date, and
the
new transctions of the next date.

I know how to insert a single row using a macro:
Selection.Insert Shift:=x1Down

But I can't seem to figure out how to write the IF statement to compare
the
dates in Column A and insert 3 lines instead of just one.

Would really appreciate the help

Regards,
PVANS