Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Insert Row Macro based on contents of two columns

Good morning group.

The below is a very useful macro to insert rows where the contents of
column B change.
How might it be modified so that it inserts rows where the contents of
columns A and B change?

Sub InsertRow_At_Change()
Dim i As Long
With Application
.Calculation = xlManual
.ScreenUpdating = False
End With
For i = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
If Cells(i - 1, 2) < Cells(i, 2) Then _
Cells(i, 1).Resize(1, 1).EntireRow.Insert
Next i
With Application
.Calculation = xlAutomatic
.ScreenUpdating = True
End With
End Sub

Many thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Insert Row Macro based on contents of two columns

How about simply:

If Cells(i - 1, 2) < Cells(i, 2) And Cells(i - 1, 1) < Cells(i, 1)
Then _
Cells(i, 1).Resize(1, 1).EntireRow.Insert

RBS

"5elpep" wrote in message
ups.com...
Good morning group.

The below is a very useful macro to insert rows where the contents of
column B change.
How might it be modified so that it inserts rows where the contents of
columns A and B change?

Sub InsertRow_At_Change()
Dim i As Long
With Application
.Calculation = xlManual
.ScreenUpdating = False
End With
For i = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
If Cells(i - 1, 2) < Cells(i, 2) Then _
Cells(i, 1).Resize(1, 1).EntireRow.Insert
Next i
With Application
.Calculation = xlAutomatic
.ScreenUpdating = True
End With
End Sub

Many thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Insert Row Macro based on contents of two columns

Thanks for your input RB.

Unfortunately I mis-typed my question. I meant to say how might it be
modified so that it inserts rows where the contents of
columns A OR B change?

Also I then need to change the blank row so that column C displays
"CAR", column D returns =OFFSET(D*,1,-3) and column E returns
=OFFSET(E*,1,-3).
To use a silly example:

MON 12 XKR
MON 12 FOCUS
MON 12 LAND CRUISER
TUES 13 HUMMER

Will look as below on running the code

MON 12 XKR
MON 12 FOCUS
MON 12 LAND CRUISER
CAR
TUES 13
TUES 13 HUMMER

and so on




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Insert Row Macro based on contents of two columns

Then change the And to an Or and put some extra lines of code in to get your
text "CAR" and the offsets.

RBS

"5elpep" wrote in message
oups.com...
Thanks for your input RB.

Unfortunately I mis-typed my question. I meant to say how might it be
modified so that it inserts rows where the contents of
columns A OR B change?

Also I then need to change the blank row so that column C displays
"CAR", column D returns =OFFSET(D*,1,-3) and column E returns
=OFFSET(E*,1,-3).
To use a silly example:

MON 12 XKR
MON 12 FOCUS
MON 12 LAND CRUISER
TUES 13 HUMMER

Will look as below on running the code

MON 12 XKR
MON 12 FOCUS
MON 12 LAND CRUISER
CAR
TUES 13
TUES 13 HUMMER

and so on





  #5   Report Post  
Posted to microsoft.public.excel.programming
jav jav is offline
external usenet poster
 
Posts: 1
Default Insert Row Macro based on contents of two columns

Is it possible to modified this macro so the new row, column C, contains
the sum of that group's column C values?

Thank you much!

5elpep wrote:
Good morning group.

The below is a very useful macro to insert rows where the contents of
column B change.
How might it be modified so that it inserts rows where the contents of
columns A and B change?

Sub InsertRow_At_Change()
Dim i As Long
With Application
.Calculation = xlManual
.ScreenUpdating = False
End With
For i = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
If Cells(i - 1, 2) < Cells(i, 2) Then _
Cells(i, 1).Resize(1, 1).EntireRow.Insert
Next i
With Application
.Calculation = xlAutomatic
.ScreenUpdating = True
End With
End Sub

Many thanks

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
Hiding rows or columns based on cell contents Bill H Excel Discussion (Misc queries) 3 December 16th 08 10:19 PM
macro with input msg based on cell contents Janelle S[_2_] Excel Discussion (Misc queries) 2 February 9th 08 11:47 PM
Excel Macro to Insert the contents of one column to other Dhawal Excel Discussion (Misc queries) 5 October 5th 06 01:22 PM
Insert Columns based on cell value Jill[_7_] Excel Programming 1 September 11th 04 09:33 AM
Macro to Sort Automatically Based on Contents of Drop-down Box Ashleigh K. Excel Programming 1 August 25th 03 10:05 PM


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