excelシートにシート番号を振る方法

どうも、star officeだと、簡単に関数一つで終わり!なんですけれど、microsoft excelだといちいち大変です。
とか言いつつも、便利な関数があるんでしょうけれどね…。
シートを分けて連続した書類を管理している場合に、ページ番号を振る必要が当然あったりしますが、シートを移動したり、いろいろといじる中で、どんどんページ番号が入れ替わったりします。
それで、いつでも最新の状態のページ番号を振りたい訳で、ある仕事をしているときに、面倒だったのでマクロを作りました。
数字を記載しているのは、以下の部分です。

1
2
3
            Worksheets(intSheetCnt).Select         'シートを指定
            ActiveSheet.Range("BK2:BL3").Select  '数字をいれるセルを指定
            ActiveCell.FormulaR1C1 = intSheetCnt  '数字をいれる

それ以外は、そこに進むまで必要となるものです。適当に読んでください。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Sub setpageNum()
    Dim intSheetCnt As Integer
    Dim intForCnt   As Integer
    Dim intAscii    As Integer
    'シート数の初期値
    intSheetCnt = 2
    intAscii = Asc("b") - 2
    Do Until Worksheets.Count < intSheetCnt
        intForCnt = 0
        intAscii = intAscii + 2
            If Worksheets.Count < intSheetCnt Then
                Exit Sub
            End If
            Worksheets(intSheetCnt).Select
            ActiveSheet.Range("BK2:BL3").Select
            ActiveCell.FormulaR1C1 = intSheetCnt
            intSheetCnt = intSheetCnt + 1
 
        If Worksheets.Count < intSheetCnt Then
            Exit Do
        End If
    Loop
 
    Worksheets(1).Select
 
 
End Sub

Tagged with:
 

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

*

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <img localsrc="" alt=""> <pre lang="" line="" escaped="" highlight="">