I am attempting to determine where page breaks occur as I am writing to a worksheet. This seems rather simple at the onset. However, I am copying rows from another worksheet and then setting the Row Height to that of the copied row. So the page break can come at any variable place in the worksheet. I use the following code to find a page break: NOTE: If there is a function that I should use to add the code in this message, tell me as I don't know just what I am doing!
=====
If ActiveCell.EntireRow.PageBreak <> -4142 Then '(NOTE: I found this on the Internet somewhere - I don't like codes like this but ???)
MsgBox "Break above this cell"
Range("A" & Control_Row_Value - 2).EntireRow.Insert
Range("A" & Control_Row_Value - 2).Value = "Header Inserted Here"
Control_Row_Value = Control_Row_Value + 1
Range("A" & Control_Row_Value).Value = "zzzzz" 'Just printing something to see which row I have.
Merge_Header_1
End If
=====
This "sort of works" but gives me a page break indication above the current_row that I am writing to.
At this point I insert a new row, and place the heading there, then move my current_row to current_ row +1
This is well and good until I insert a row who's Row Height does not make the page break. Below is the code that I am using to copy a row from a second Worksheet and adjust it's height. Seems like I should be ale to use this routine on the inserted Row for the Page Header. I will try that. I think that this does not make any sense. Seems Like I need to set the inserted row Height to a row with the largest Row Height. ???? Can't explain too well here.)
This code below is used on every row that I copy from FORMAT to the current worksheet.
Control_Header_Row is the row value of the row copied from FORMAT. There are about 20 different rows in the FORMAT worksheet. The user of this application can change the row of any or all rows on the FORMAT worksheet so that the resultant output fits their needs.
=====
Sheets("FORMAT").Range("A" & Control_Header_Type & ":I" & Control_Header_Type).Copy _
Destination:=ActiveSheet.Range("A" & Control_Row_Value)
Control_Row_Highest = ActiveSheet.UsedRange.Rows.Count 'Need to have highest row as we added something
Range("A" & Control_Row_Highest).Select
Selection.RowHeight = Sheets("FORMAT").Range("A" & Control_Header_Type).RowHeight
=====
The first line does the copy from Sheet "FORMAT" to the Current_Row_Value in the active worksheet. The row copied is Control_Header_Type
The next line just tracks the Highest Row that has had data added to it.
The next line selects that row (should be the just copied row from FORMAT) to make it the active row.
The next line sets the Row Height of the row just copied to the Row Height of the row in the FORMAT worksheet.
NOTE: I track the Highest Row so that I can set the Print Area when I have finished processing. There is probably a much easier way to do that?
=====
There continues to be a bit of guess work involved so I am wondering someone can improve on this or has has a better answer?
Thank you in advance for your help.
Sorry for how confusing this must seem. Perhaps someone can understand????
Dan Foltz
Thanks in advance for any help you might provide.
=====
If ActiveCell.EntireRow.PageBreak <> -4142 Then '(NOTE: I found this on the Internet somewhere - I don't like codes like this but ???)
MsgBox "Break above this cell"
Range("A" & Control_Row_Value - 2).EntireRow.Insert
Range("A" & Control_Row_Value - 2).Value = "Header Inserted Here"
Control_Row_Value = Control_Row_Value + 1
Range("A" & Control_Row_Value).Value = "zzzzz" 'Just printing something to see which row I have.
Merge_Header_1
End If
=====
This "sort of works" but gives me a page break indication above the current_row that I am writing to.
At this point I insert a new row, and place the heading there, then move my current_row to current_ row +1
This is well and good until I insert a row who's Row Height does not make the page break. Below is the code that I am using to copy a row from a second Worksheet and adjust it's height. Seems like I should be ale to use this routine on the inserted Row for the Page Header. I will try that. I think that this does not make any sense. Seems Like I need to set the inserted row Height to a row with the largest Row Height. ???? Can't explain too well here.)
This code below is used on every row that I copy from FORMAT to the current worksheet.
Control_Header_Row is the row value of the row copied from FORMAT. There are about 20 different rows in the FORMAT worksheet. The user of this application can change the row of any or all rows on the FORMAT worksheet so that the resultant output fits their needs.
=====
Sheets("FORMAT").Range("A" & Control_Header_Type & ":I" & Control_Header_Type).Copy _
Destination:=ActiveSheet.Range("A" & Control_Row_Value)
Control_Row_Highest = ActiveSheet.UsedRange.Rows.Count 'Need to have highest row as we added something
Range("A" & Control_Row_Highest).Select
Selection.RowHeight = Sheets("FORMAT").Range("A" & Control_Header_Type).RowHeight
=====
The first line does the copy from Sheet "FORMAT" to the Current_Row_Value in the active worksheet. The row copied is Control_Header_Type
The next line just tracks the Highest Row that has had data added to it.
The next line selects that row (should be the just copied row from FORMAT) to make it the active row.
The next line sets the Row Height of the row just copied to the Row Height of the row in the FORMAT worksheet.
NOTE: I track the Highest Row so that I can set the Print Area when I have finished processing. There is probably a much easier way to do that?
=====
There continues to be a bit of guess work involved so I am wondering someone can improve on this or has has a better answer?
Thank you in advance for your help.
Sorry for how confusing this must seem. Perhaps someone can understand????
Dan Foltz
Thanks in advance for any help you might provide.