+ Reply to Thread
Results 1 to 3 of 3

Insert header , hide rows and insert page breaks

Hybrid View

dwx Insert header , hide rows and... 09-15-2013, 03:20 AM
dwx Re: Insert header , hide rows... 09-15-2013, 07:55 AM
jaslake Re: Insert header , hide rows... 09-16-2013, 10:10 AM
  1. #1
    Registered User
    Join Date
    09-15-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    56

    Insert header , hide rows and insert page breaks

    Original layout in sheet1 and desired outcome in sheet2

    Pagebreak Example.xlsx

    1) to insert the company/date edited header box above each name/ID box.

    2) Hide Binary PW box

    3) insert page break, to be able to print a piece of, from company box to multi ID box for each person.

  2. #2
    Registered User
    Join Date
    09-15-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: Insert header , hide rows and insert page breaks

    anyone able to help?

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Insert header , hide rows and insert page breaks

    Hi dwx

    This Code is in the attached and appears to do as you require
    Option Explicit
    ' Adapted From http://www.excelforum.com/excel-programming-vba-macros/846098-macro-to-take-data-from-sht1-and-rearrange-on-sht2.html?p=2867102
    Sub Do_Me()
        Dim ws As Worksheet, ws1 As Worksheet
        Dim lLoop As Long, i As Long
        Dim rFoundCell As Range
        Dim myRegion As String, myStart As String
        Dim myHeads As Variant, myStyle As Variant
    
        myStyle = Array("xlEdgeLeft", "xlEdgeTop", "xlEdgeRight", "xlEdgeBottom")
    
        Set ws = Sheets("Original")
        Application.ScreenUpdating = False
    
        If Not Evaluate("ISREF(Desired!A1)") Then
            Worksheets.Add(After:=Sheets(1)).Name = "Desired"
        Else
            Sheets("Desired").Cells.Clear
        End If
    
        Set ws1 = Sheets("Desired")
    
        ws.Cells.Copy ws1.Range("A1")
        With ws1
            .Cells.EntireRow.Hidden = False
            myHeads = .Range("A4:B5")
            With Columns(1)
                Set rFoundCell = .Cells(1, 1)
                For lLoop = 1 To WorksheetFunction.CountIf(.Cells, "Name:")
                    Set rFoundCell = .Find(What:="Name:", After:=rFoundCell, _
                            LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, MatchCase:=False)
                    myRegion = rFoundCell.CurrentRegion.Address(True, True)
                    myStart = Split(myRegion, ":")(0)
                    If Not .Range(myStart).Offset(-2, 0).Value = "Date edited:" Then
                        .Range(myStart).Offset(-2, 0).Resize(2, 1).EntireRow.Insert
                        .Range(myStart).Offset(-1, 0).Resize(2, 2).Value = myHeads
                        For i = LBound(myStyle) To UBound(myStyle)
                            With .Range(myStart).Offset(-1, 0).Resize(2, 4).Borders
                                .LineStyle = xlContinuous
                                .Weight = xlMedium
                            End With
                        Next i
                        .Range(myStart).Offset(-1, 0).Resize(2, 4).Borders(xlInsideVertical).LineStyle = xlNone
                        .Range(myStart).Offset(-1, 0).Resize(2, 4).Borders(xlInsideHorizontal).LineStyle = xlNone
                    End If
                Next lLoop
            End With
    
            With Columns(1)
                Set rFoundCell = .Cells(1, 1)
                For lLoop = 1 To WorksheetFunction.CountIf(.Cells, "Binary PW")
                    Set rFoundCell = .Find(What:="Binary PW", After:=rFoundCell, _
                            LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, MatchCase:=False)
                    myRegion = rFoundCell.CurrentRegion.Address(True, True)
                    .Range(myRegion).EntireRow.Hidden = True
                Next lLoop
            End With
        End With
        Call PageBreaks
        Application.ScreenUpdating = True
    End Sub
    and
    'From http://www.vbaexpress.com/kb/getarticle.php?kb_id=180
    Sub PageBreaks()
        Dim ws1 As Worksheet
        Dim LR As Long
        Dim c As Range
        Dim FirstAddress As String, Search As String
    
        Set ws1 = Sheets("Desired")
        With ws1
            LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                    SearchDirection:=xlPrevious).Row
            .ResetAllPageBreaks
        End With
        With ws1.PageSetup
            .PrintArea = ""
            .PrintArea = "A4:D" & LR
        End With
    
        Search = "Company:"
    
        With ws1.Columns(1)
            Set c = .Find(What:=Search, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True)
            If Not c Is Nothing Then
                FirstAddress = c.Address
                Do
                    On Error Resume Next
                    ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=c
                    On Error GoTo 0
                    Set c = .FindNext(c)
                Loop While Not c Is Nothing And c.Address <> FirstAddress
            End If
        End With
    End Sub
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 7
    Last Post: 04-29-2013, 08:38 PM
  2. Replies: 0
    Last Post: 01-25-2013, 12:05 PM
  3. VBA to insert page breaks
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-27-2012, 11:27 PM
  4. Insert Page Breaks
    By NickHubble in forum Excel General
    Replies: 1
    Last Post: 04-05-2010, 08:07 AM

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