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
Bookmarks