|    | 
     はじめましてこんばんわ。 
 
今31行でフォーマットを作成して、それ毎に改ページをするプログラムを 
作っています。改ページの方は色々調べてできたのですが、フォーマット作成で 
For文で繰り返しても同じ箇所に書いているので、セルの進め方が分りません。 
行き詰ってしまい質問しにきました。 
どなたか教えていただけないでしょうかよろしくお願い致します。 
 
高さ24.5 幅2.00 
 
下記のプログラムで動かしています↓ 
 
Sub Macro1() 'フォーマットを作成 
For MyBreakCount = 1 To 3 
  Range("B2:AF31").Select 
  Selection.Borders(xlDiagonalDown).LineStyle = xlNone 
  Selection.Borders(xlDiagonalUp).LineStyle = xlNone 
  With Selection.Borders(xlEdgeLeft) 
    .LineStyle = xlContinuous 
    .Weight = xlThin 
    .ColorIndex = xlAutomatic 
  End With 
  With Selection.Borders(xlEdgeTop) 
    .LineStyle = xlContinuous 
    .Weight = xlThin 
    .ColorIndex = xlAutomatic 
  End With 
  With Selection.Borders(xlEdgeBottom) 
    .LineStyle = xlContinuous 
    .Weight = xlThin 
    .ColorIndex = xlAutomatic 
  End With 
  With Selection.Borders(xlEdgeRight) 
    .LineStyle = xlContinuous 
    .Weight = xlThin 
    .ColorIndex = xlAutomatic 
  End With 
  Selection.Borders(xlInsideVertical).LineStyle = xlNone 
  Selection.Borders(xlInsideHorizontal).LineStyle = xlNone 
  With Selection.Interior 
    .ColorIndex = 2 
    .Pattern = xlSolid 
    .PatternColorIndex = xlAutomatic 
  End With 
  Range("Y14").Select 
  Application.Goto Reference:="Macro1" 
Next 
End Sub 
 
Sub MyHPBreaksAdd()  '改ページを設定する 
MyHPBreaksReset   '現在の改ページクリア 
With Worksheets(1) 
For MyBreakCount = 1 To 3   '4ページ作る場合 
'31行毎の場合 
.HPageBreaks.Add Before:=Cells(MyBreakCount * 31 + 1, 1) 
  
'空だとページとして認識しないので数字を入れる 
Cells(MyBreakCount * 31 + 1, 1).Value = MyBreakCount + 1 & "ページ" 
Next 
End With 
MyHPBreaksCount  'ページ数を取得して、MsgBoxで表示 
End Sub 
Sub MyHPBreaksReset() '現在の改ページクリア 
With Worksheets(1) 
.ResetAllPageBreaks '現在の改ページクリア 
For MyBreakCount = 1 To 3 
.Cells(MyBreakCount * 31 + 1, 1).Value = "" '数字クリア 
Next 
End With 
End Sub 
 
Sub MyHPBreaksCount()  'ページ数を取得して、MsgBoxで表示 
With Worksheets(1) 
MyBreaksCount = .HPageBreaks.Count + 1 
MsgBox MyBreaksCount 
End With 
End Sub 
 | 
     
    
   |