+ Reply to Thread
Results 1 to 2 of 2

Macro to transfer data onto printable sheet

  1. #1
    Registered User
    Join Date
    11-21-2009
    Location
    Rhyl, North Wales
    MS-Off Ver
    Excel 2003
    Posts
    39

    Macro to transfer data onto printable sheet

    Hi there, i've abit of a problem, i'n currently working on a macro that will transfer some details onto a sheet setup for printouts. I've attached a screen shot and will now try to explain how far i am and what i'm struggling with. Ok so in the screen shot you can see the Printable sheet (columns A:H) with all the data need listed in in sections on Columns O:P (will be O:W), a small table at J2:M13 show the structure of the O:P listed data (ie: entries per section and relitive start and stop rows for each section). Underneath this table is a copy just listed by entries decending order.

    So far i've wrote a macro that will lookup the first sections entry value (Cranes, K26 "45") then start copying over the details ( from columns O:P) until either all entries have been copied or until the first printout page is full, here is where i become stuck.

    in the first instance i need to check if there is enough space left on the sheet for the next section of data ( Tickets, K27 "37") to be added and if not cycle thru the remaining entries to fill the space, in the second instance i need to finish adding the data at the top of the next sheet, hope this all makes sense. i'll add the code i've come up with so far, any help/suggestions would be appreciated, thanks.

    Sub Test()

    X = 1
    Status " & 1 = 0"

    TableStart = 7
    TableFinish = 53

    TitleBar = Range("A5:H5")

    n = 26
    Entries = Range("K" & n).Value ' 45
    DataStartRow = Range("L" & n).Value ' 101
    DataEndRow = Range("M" & n).Value ' 145
    TableStartRow = 7

    Available = Range("B" & TableStart & ":B" & TableFinish).Cells.SpecialCells(xlCellTypeBlanks).Count

    iCount = 0
    iDataRowCount = DataStartRow
    iTableRowCount = TableStartRow
    iAvailable = Available

    Do Until iCount = Entries Or iCount = Available

    Range("B" & iTableRowCount).Value = Range("P" & iDataRowCount).Value
    Range("C" & iTableRowCount).Value = Range("O" & iDataRowCount).Value
    Range("N" & iTableRowCount).Value = "1"

    iCount = iCount + 1
    iAvailable = iAvailable - 1
    iTableRowCount = iTableRowCount + 1
    iDataRowCount = iDataRowCount + 1
    Loop

    If iCount = Entries Then GoTo Stage2:
    ElseIf iCount = Available Then GoTo Stage3:

    '---------------------------------------------------------------------------------------------------
    'If iCount = Entries (full table entered, Check available space, will the next table fit, if so do it, if not will any other table fit )
    Stage2:
    Status1 = 1

    n = n + 1

    Available = Range("B" & TableStart & ":B" & TableFinish).Cells.SpecialCells(xlCellTypeBlanks).Count

    If Entries <= Available - 1 Then

    Range("N1").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Select

    iRow = ActiveCell.Row
    iCount = 0
    iDataRowCount = DataStartRow
    iTableRowCount = TableStartRow
    iAvailable = Available

    TitleBar.Copy Destination:=Range("A" & iRow & ":H" & iRow)
    Range("A" & iRow & ":H" & iRow).Value = Entries.Offset(0, -1).Value

    Do Until iCount = Entries Or iCount = Available

    Range("B" & iTableRowCount).Value = Range("P" & iDataRowCount).Value
    Range("C" & iTableRowCount).Value = Range("O" & iDataRowCount).Value
    Range("N" & iTableRowCount).Value = "1"

    iCount = iCount + 1
    iAvailable = iAvailable - 1
    iTableRowCount = iTableRowCount + 1
    iDataRowCount = iDataRowCount + 1
    Loop

    ElseIf Entries > Available Then



    '----------------------------------------------------------------------------------------------------




    End Sub
    Attached Files Attached Files

  2. #2
    Forum Contributor wamp's Avatar
    Join Date
    11-10-2008
    Location
    Norway
    MS-Off Ver
    97, 2000 & 2003 (diff. workstations)
    Posts
    184

    Re: Macro to transfer data onto printable sheet

    Please change your post to comply with the forum rules (put codetags around your code)

    also, it will be a lot easier for those wanting to help you, if you attach a sample workbook rather than an image.

+ 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