' 頁の先頭行のセルに、小見出しへのリンクを
' 貼り付ける。
' 既にリンクが存在するセルは一旦リンクを解除します。
' 2008/2/11
Sub Main()
Dim nRowLast, nColLast, nCol As Integer
Dim nRowPrev As Integer
nCol = 2 ' 小見出しの列番号(1オリジン)
nRowPrev = 2 ' 小見出しの開始行番号(1オリジン)
'
nRowLast = 0
nColLast = 0
' 最初のリンク元行番号を0に設定
With ActiveSheet
For Each objPageBreak In .HPageBreaks
Dim nRow As Integer
' 改ページのある行番号を取得
nRowPageBreak = objPageBreak.Location
' リンク元行番号から改ページのある行番号までで
' 文字が入っているセル番号を取得。
' ・複数ある場合は後勝ち
' ・数式が入っているセルはクリアしながら
For nRow = nRowPrev To nRowPageBreak - 1
If Cells(nRow, nCol).HasFormula = True Then
Cells(nRow, nCol) = Null
End If
If Cells(nRow, nCol).Value <> "" Then
nRowLast = nRow
nColLast = nCol
End If
Next
If (nRowLast <> 0) Then
Cells(nRowPageBreak, nCol).FormulaR1C1 = "=R" & Format(nRowLast) & "C" & Format(nColLast)
End If
nRowPrev = nRowPageBreak + 1
Next
End With
End Sub
' 貼り付ける。
' 既にリンクが存在するセルは一旦リンクを解除します。
' 2008/2/11
Sub Main()
Dim nRowLast, nColLast, nCol As Integer
Dim nRowPrev As Integer
nCol = 2 ' 小見出しの列番号(1オリジン)
nRowPrev = 2 ' 小見出しの開始行番号(1オリジン)
'
nRowLast = 0
nColLast = 0
' 最初のリンク元行番号を0に設定
With ActiveSheet
For Each objPageBreak In .HPageBreaks
Dim nRow As Integer
' 改ページのある行番号を取得
nRowPageBreak = objPageBreak.Location
' リンク元行番号から改ページのある行番号までで
' 文字が入っているセル番号を取得。
' ・複数ある場合は後勝ち
' ・数式が入っているセルはクリアしながら
For nRow = nRowPrev To nRowPageBreak - 1
If Cells(nRow, nCol).HasFormula = True Then
Cells(nRow, nCol) = Null
End If
If Cells(nRow, nCol).Value <> "" Then
nRowLast = nRow
nColLast = nCol
End If
Next
If (nRowLast <> 0) Then
Cells(nRowPageBreak, nCol).FormulaR1C1 = "=R" & Format(nRowLast) & "C" & Format(nColLast)
End If
nRowPrev = nRowPageBreak + 1
Next
End With
End Sub