选择页面的最后一行 [英] Selecting the last row on a page
问题描述
在Excel工作表上,我每20行有一个分页符(不包括数据第一页上的标题),因此在打印时,每张表只有20行。
我想突出显示每页最后一行的第一列,即使数据行少于20行(例如,最后一页只有11行,但最后一行应该仍然会突出显示) 但我不确定该怎么做。
我能找到Ron de Bruin的页面,找到活动表格中的最后一行,一列或最后一个单元格。
Sub LastRowInOneColumn()
'查找列中的最后一行:本例中的列A
Dim LastRow As Long
使用ActiveSheet
LastRow = .Cells(.Rows.Count," A")。结束(xlUp)。行
结束
MsgBox LastRow
结束子
Sub LastColumnInOneRow()
'查找行中最后使用的列:此示例中的第1行
Dim LastCol As Integer
使用ActiveSheet
LastCol = .Cells( 1,.Columns.Count)。End(xlToLeft).Column
以
结束MsgBox LastCol
End Sub
如何修改它以便选择表格中每个分页符的最后一行?
Dim r As Long
Dim m As Long
Application.ScreenUpdating = False
m = Cells.Find(What:=" *" ;, SearchOrder:= xlByRows,SearchDirection:= xlPrevious).Row
对于r = 21至m步骤20
范围("A") &安培; r).Resize(1,3).Interior.Color = vbYellow
下一个r
'最后一行
如果m Mod 20<> 1然后
范围("A"& m).Resize(1,3).Interior.Color = vbYellow
结束如果
Application.ScreenUpdating = True
End Sub
On an excel sheet I have a page break for every 20 rows (not counting the headers on the first page of data), so that when printed, there are only 20 rows for each sheet.
I would like to highlight the first column of the last row of each page, even if there are less than 20 rows of data (e.g. the last page has only 11 rows, but that last row should still be highlighted) but I'm unsure how to do that.
I was able to find Ron de Bruin's page on finding the last row, column or last cell in an active sheet.
Sub LastRowInOneColumn() 'Find the last used row in a Column: column A in this example Dim LastRow As Long With ActiveSheet LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row End With MsgBox LastRow End Sub Sub LastColumnInOneRow() 'Find the last used column in a Row: row 1 in this example Dim LastCol As Integer With ActiveSheet LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column End With MsgBox LastCol End Sub
How can this be modified so that it selects the last row on each page break in the sheet?
For example:
Sub HighlightLast() Dim r As Long Dim m As Long Application.ScreenUpdating = False m = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row For r = 21 To m Step 20 Range("A" & r).Resize(1, 3).Interior.Color = vbYellow Next r ' Last row If m Mod 20 <> 1 Then Range("A" & m).Resize(1, 3).Interior.Color = vbYellow End If Application.ScreenUpdating = True End Sub
这篇关于选择页面的最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!