LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Macro - Find Next Change In A Column; then insert row

Thanks again Gary, that's also perfect. The only thing is it adds a worksheet
that is blank after every few new correct worksheets. Is there an easy way to
delete a sheet if it's completely blank?

Thanks again!


"Gary Keramidas" wrote:

you can try this, probably a simpler way. watch for word wrap in the code when
you paste it.

Sub test()
Dim ws As Worksheet
Dim i As Long, cntr As Long
Dim lastrow As Long
Dim newSht As Worksheet
Set ws = Worksheets("sheet1")
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For i = lastrow To 2 Step -1
With ws
If .Range("A" & i) < .Range("A" & i - 1) Then
.Range("A" & i).EntireRow.Insert
Else
cntr = cntr + 1
GoTo cont:
End If
cntr = 1 + cntr
Set newSht =
Worksheets.Add(after:=Worksheets(Worksheets.Count) )
.Range("A" & i + 1 & ":B" & i + cntr).Copy _
newSht.Range("A1")
cntr = 0
End With
cont:
Next
End Sub

--


Gary


"masterbaker" wrote in message
...
Thanks Gary - That's Perfect

Seeing how fast you responded, could you shoot me some VB that would then
take this separated data and copy each section of similar data and paste it
into a new tab. That is, each grouping created by this blank inserted rows is
copied to a new tab until all groups are placed in new tabs.

Thanks a ton, your code is perfect!


"Gary Keramidas" wrote:

this may be one way, assuming the data starts in row2 of column A

Sub test()
Dim ws As Worksheet
Dim i As Long
Dim lastrow As Long
Set ws = Worksheets("sheet1")
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row

For i = lastrow To 2 Step -1
With ws
If .Range("A" & i) < .Range("A" & i - 1) Then
.Range("A" & i).EntireRow.Insert
End If
End With
Next
End Sub

--


Gary


"masterbaker" wrote in message
...
This has to be possible and someone knows how to do it: I need a Macro that
will scan down a column and insert a row before the next change in values.
It's essentially similar to the subtotal function where you select "at each
change in:" but I need a way to break up tons of data sorted within a
column
but the values are not static.

Sample Data:

Column A Column B
apple 25
apple 30
grape 26
grape 28
cherry 24
pear 27

Without knowing the actual values in column A, I need a macro that will
insert a row between apple/grape and then grape/cherry and then cherry/pear
and so on down the worksheet. I have tried a macro that uses the find
function, but I have to know what the values in column A are going to be,
which I don't.

This would be HUGE if possible. Please help!









 
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
Find & Replace and Find & Insert macro help needed RS Excel Programming 2 January 29th 07 07:35 AM
Find emty cell in column and insert value Mikus Excel Programming 3 August 17th 05 01:47 PM
macro to Insert rows at every change in a column [email protected] Excel Programming 4 August 3rd 05 01:57 PM
Need Macro to Find Column Heading -- if none, then insert new column Jeff[_43_] Excel Programming 0 December 15th 04 07:08 AM
find row value, insert column gaba Excel Programming 0 October 18th 04 06:59 PM


All times are GMT +1. The time now is 03:41 PM.

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"