Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Inserting A Row Where Data Changes

I am very new to VBA so any help would much appreciated.

I would like to know how to write a macro that inserts an entire row
of cells everytime the the data in cell b is different from the cell
above it. It would need to be a continuous process until there was no
more data.

eg.

A B

10 40
12 40 < Insert a row between the 40 and 60
17 60
22 60 < Insert a row between the 60 and 70
24 70
29 70

Dim i As Integer
i = 2
While Range("C" & i) < ""
Do
If Range("C" & i) < Range("C" & i + 1) Then
Rows(i & ":" & i + 1).Insert Shift:=xlDown
i = i + 1
End If
i = i + 1
Loop
Wend

The above was some code that I came up with but I am pulling my hair
out trying to make it work

Thanks for any help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Inserting A Row Where Data Changes

Hi
This sample code will insert a blank row every time value entered in column
B is different from value one row above.
Right-click on your worksheet's tab, choose View code and paste the
following exemple :

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column < 2 Or Target.Row = 1 Then Exit Sub
If Target.Offset(-1, 0).Value < Target.Value Then
Target.EntireRow.Insert
End If
End Sub

HTH
Cordially
Pascal

"TP" a écrit dans le message de
om...
I am very new to VBA so any help would much appreciated.

I would like to know how to write a macro that inserts an entire row
of cells everytime the the data in cell b is different from the cell
above it. It would need to be a continuous process until there was no
more data.

eg.

A B

10 40
12 40 < Insert a row between the 40 and 60
17 60
22 60 < Insert a row between the 60 and 70
24 70
29 70

Dim i As Integer
i = 2
While Range("C" & i) < ""
Do
If Range("C" & i) < Range("C" & i + 1) Then
Rows(i & ":" & i + 1).Insert Shift:=xlDown
i = i + 1
End If
i = i + 1
Loop
Wend

The above was some code that I came up with but I am pulling my hair
out trying to make it work

Thanks for any help



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
Inserting a row and filling in data Idolminder Excel Discussion (Misc queries) 1 October 22nd 08 06:51 PM
Inserting data question Dennis G Excel Discussion (Misc queries) 1 October 11th 08 06:44 AM
locate data from a chart by inserting data into a cell Aaron Hodson \(Coversure\) Excel Worksheet Functions 3 November 1st 07 12:12 PM
Inserting Data CJ Excel Discussion (Misc queries) 5 April 3rd 06 04:06 AM
Inserting row of data Fisch Excel Programming 0 July 30th 03 08:42 PM


All times are GMT +1. The time now is 05:32 PM.

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"