Macro Help?

SirQuej

New Member
Joined
Feb 2, 2018
Messages
12
Hi Guys

I'm looking a Macro to help with a repetitive job I have every month? Below is an example of a spreadsheet I run each month and currently I have to go down the spreadsheet manually and insert two lines between each unique ident, then a single blank line between each date within each ident...I then have to put page breaks between each Ident group....

So this is how it looks when I start:

Ident SurvAddress Date SystRef
1 *************** 01/08/20 *********
1 *************** 01/08/20 *********
1 *************** 02/08/20 *********
1 *************** 02/08/20 *********
2 *************** 01/08/20 *********
2 *************** 01/08/20 *********
2 *************** 02/08/20 *********
2 *************** 02/08/20 *********
3 *************** 01/08/20 *********
3 *************** 01/08/20 *********
3 *************** 02/08/20 *********
3 *************** 02/08/20 *********
4 *************** 01/08/20 *********
4 *************** 01/08/20 *********
4 *************** 02/08/20 *********
4 *************** 02/08/20 *********


And this is how I need it to look:

Ident SurvAddress Date SystRef
1 *************** 01/08/20 *********
1 *************** 01/08/20 *********

1 *************** 02/08/20 *********
1 *************** 02/08/20 *********

Page Break
2 *************** 01/08/20 *********
2 *************** 01/08/20 *********

2 *************** 02/08/20 *********
2 *************** 02/08/20 *********

Page Break
3 *************** 01/08/20 *********
3 *************** 01/08/20 *********

3 *************** 02/08/20 *********
3 *************** 02/08/20 *********

Page Break
4 *************** 01/08/20 *********
4 *************** 01/08/20 *********

4 *************** 02/08/20 *********
4 *************** 02/08/20 *********

The spreadsheet is thousands of lines long so any help would be appreciated.

Thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
just for others, how wide is the data (columns), do they start in A, what are your unique identifiers, currtly it looks like two dates only. Can you have more than two before a page break as that will produce thousands of pages ?
 
Upvote 0
just for others, how wide is the data (columns), do they start in A, what are your unique identifiers, currtly it looks like two dates only. Can you have more than two before a page break as that will produce thousands of pages ?

Hi Mole999

The first column is column A yes. The columns can be variable widths. The unique identifiers are the Ident column (column A) and the date Column (Column C).

Each unique ident will have a full months worth of dates, so yes, there will be more dates. I simplified it for this exercise. The page breaks only need to be between each unique IDENT, not each date as well..
 
Upvote 0
Right, so incredibly, I managed to solve this myself (which if you knew my VB skill level, you would be amazed)...

I ended up using TWO separate Macro's...one splits it by ident and inserts the page break...the 2nd one then splits it by date....I've run them and they worked a treat...

Posted below in case anyone is interested....

VBA Code:
Sub SplitIdent()
'
' Macro4 Macro
'
' Keyboard Shortcut: Ctrl+a
'
Dim Ident
Dim Index As Integer

For Index = 1 To 10000
Ident = ActiveCell.Value
   ActiveCell.Offset(1, 0).Activate
   ActiveCell.Value = ActiveCell
       If ActiveCell.Value = Ident Then
       Ident = ActiveCell.Value
       ElseIf ActiveCell.Value <> Ident Then
       ActiveCell.EntireRow.Insert
       ActiveCell.EntireRow.Insert
       ActiveCell.Offset(2, 0).Activate
       ActiveWindow.SelectedSheets.HPageBreaks.Add ActiveCell.Offset(-1, 0)
       End If
Next

End Sub





Sub SplitDate()
'
' Macro2 Macro
'
' Keyboard Shortcut: Ctrl+b
'

Dim Ident
Dim Index As Integer

For Index = 1 To 10000
Ident = ActiveCell.Value
    ActiveCell.Offset(1, 0).Activate
    ActiveCell.Value = ActiveCell
        If ActiveCell.Value = Ident Then
        Ident = ActiveCell.Value
        ElseIf ActiveCell.Value <> Ident Then
        ActiveCell.EntireRow.Insert
        ActiveCell.Offset(1, 0).Activate
        End If
Next

End Sub
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,980
Members
448,934
Latest member
audette89

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top