+ Reply to Thread
Results 1 to 4 of 4

seperating data

  1. #1
    Alan M
    Guest

    seperating data

    I have a sheet with ( amongst other data) a column containing a series of
    prices in ascending order.

    I need code to seperate them into ranges such a £0-£4000, $4001 - £6000,
    £6001-£8000 and so on to £20,000. I would like to insert three blank rows
    after each range so that I can add summary information on each range into
    these rows.

    Can you help please?

  2. #2
    Tom Ogilvy
    Guest

    RE: seperating data

    Assume you numbers are in column C and C1 contains a label.

    Sub Insertrows()
    lastrow = Cells(Rows.Count, "C").End(xlUp).Row
    Cat1 = (Cells(lastrow, "C") - 1) \ 4000
    For i = lastrow To 2 Step -1
    Cat = (Cells(i, "C") - 1) \ 4000
    If Cat <> Cat1 Then
    Cells(i + 1, 1).Resize(3).EntireRow.Insert
    End If
    Cat1 = Cat
    Next
    End Sub

    --
    Regards,
    Tom Ogilvy


    "Alan M" wrote:

    > I have a sheet with ( amongst other data) a column containing a series of
    > prices in ascending order.
    >
    > I need code to seperate them into ranges such a £0-£4000, $4001 - £6000,
    > £6001-£8000 and so on to £20,000. I would like to insert three blank rows
    > after each range so that I can add summary information on each range into
    > these rows.
    >
    > Can you help please?


  3. #3
    Alan M
    Guest

    RE: seperating data

    Hi Tom,


    Thanks for the help. The code you sent inserts rows below the 0-4000 range.
    However I also need it torun throught the column of prices and insert rows
    below the 4001-6000 prices, the 6001- 8000 prices and so on so I have several
    rows of prices in each range separated by three blank rows.

    "Tom Ogilvy" wrote:

    > Assume you numbers are in column C and C1 contains a label.
    >
    > Sub Insertrows()
    > lastrow = Cells(Rows.Count, "C").End(xlUp).Row
    > Cat1 = (Cells(lastrow, "C") - 1) \ 4000
    > For i = lastrow To 2 Step -1
    > Cat = (Cells(i, "C") - 1) \ 4000
    > If Cat <> Cat1 Then
    > Cells(i + 1, 1).Resize(3).EntireRow.Insert
    > End If
    > Cat1 = Cat
    > Next
    > End Sub
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Alan M" wrote:
    >
    > > I have a sheet with ( amongst other data) a column containing a series of
    > > prices in ascending order.
    > >
    > > I need code to seperate them into ranges such a £0-£4000, $4001 - £6000,
    > > £6001-£8000 and so on to £20,000. I would like to insert three blank rows
    > > after each range so that I can add summary information on each range into
    > > these rows.
    > >
    > > Can you help please?


  4. #4
    Tom Ogilvy
    Guest

    RE: seperating data

    Sub Insertrows()
    Dim lastrow As Long, Cat1 As Long
    Dim Cat As Long
    lastrow = Cells(Rows.Count, "C").End(xlUp).Row
    Cat1 = (Cells(lastrow, "C") - 1) \ 2000
    If Cat1 < 1 Then Cat1 = 1
    For i = lastrow To 2 Step -1
    Cat = (Cells(i, "C") - 1) \ 2000
    If Cat < 1 Then Cat = 1
    If Cat <> Cat1 Then
    Cells(i + 1, 1).Resize(3).EntireRow.Insert
    End If
    Cat1 = Cat
    Next
    End Sub

    --
    Regards,
    Tom Ogilvy


    "Alan M" wrote:

    > Hi Tom,
    >
    >
    > Thanks for the help. The code you sent inserts rows below the 0-4000 range.
    > However I also need it torun throught the column of prices and insert rows
    > below the 4001-6000 prices, the 6001- 8000 prices and so on so I have several
    > rows of prices in each range separated by three blank rows.
    >
    > "Tom Ogilvy" wrote:
    >
    > > Assume you numbers are in column C and C1 contains a label.
    > >
    > > Sub Insertrows()
    > > lastrow = Cells(Rows.Count, "C").End(xlUp).Row
    > > Cat1 = (Cells(lastrow, "C") - 1) \ 4000
    > > For i = lastrow To 2 Step -1
    > > Cat = (Cells(i, "C") - 1) \ 4000
    > > If Cat <> Cat1 Then
    > > Cells(i + 1, 1).Resize(3).EntireRow.Insert
    > > End If
    > > Cat1 = Cat
    > > Next
    > > End Sub
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "Alan M" wrote:
    > >
    > > > I have a sheet with ( amongst other data) a column containing a series of
    > > > prices in ascending order.
    > > >
    > > > I need code to seperate them into ranges such a £0-£4000, $4001 - £6000,
    > > > £6001-£8000 and so on to £20,000. I would like to insert three blank rows
    > > > after each range so that I can add summary information on each range into
    > > > these rows.
    > > >
    > > > Can you help please?


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1