アプリ版:「スタンプのみでお礼する」機能のリリースについて

下記のマクロをExcel95とExcel2000で動かすと結果(フォーマット)が違ってきます。
何処をどの様に修正すれば良いか教えてもらえないでしょうか。
言語の意味も出来たら教えてもらえますか。よろしくお願いします。
尚、省略している所があります。(言語は800文字以上は遅れませんので)
Sheets("印刷").Select
Dim gyo, cout, st, a, burank, st2, burank2
Dim total As Integer
Dim tt As String
cout = 1
Range("a3").Select
total = 2
Do
total = total + 1
burank = Worksheets("印刷").Cells(total, 25).Text
Loop While burank <> ""
total = total - 2
For a = 3 To total

If a = 3 Then
Range(Cells(a, 3), Cells(a, 26)).Select
With Selection.Borders(xlBottom)
.Weight = xlHairline
End With
Else

'
burank1 = Worksheets("印刷").Cells(a + 1, 2).Text
st = Worksheets("印刷").Cells(a, 1).Text
If st = "" And burank1 <> "" Then
'
Range(Cells(a, 2), Cells(a, 2)).Select
ActiveCell.Formula = "小 計"
'
With Selection
.HorizontalAlignment = xlCenter
End With
gyo = a + 1
Range(Cells(a, 1), Cells(a, 26)).Select
With Selection.Borders(xlLeft)
.Weight = xlThin
'
End With

A 回答 (3件)

>結果(フォーマット)が違ってきます



どのように違うかはEXCEL95を使用していないため、記憶に頼っていますが、罫線の設定で定数や実行結果に変更があったように思います(97の時?)。
EXCEL95の定数 xlLeft、xlBottom は、変更されて以下のようになっています。
xlEdgeLeft、xlEdgeBottom 
(xlBordersIndexのメンバです)

この当たりの関係では?
    • good
    • 0

コードの意味は『○』を付けた箇所に書いてみました。



修正箇所としては、<<  ⇒  >> とした3箇所を修正してみてください。
実際、動かすことができないので見ただけの産物です。うまくいけばいいですが。

○シート印刷を選択
Sheets("印刷").Select
○配列の宣言。チャンと宣言したほうがいいか
Dim gyo, cout, st, a, burank, st2, burank2
Dim total As Integer
Dim tt As String

cout = 1
○A3を選択。多分、表の左上でしょう
Range("a3").Select

total = 2
○3行目から、データが入力された行数をカウントしている
Do
 total = total + 1
 burank = Worksheets("印刷").Cells(total, 25).Text
Loop While burank <> ""

○行数を余分に数えたので引いているが、これでは最終行-1の行数か。
total = total - 2

○3行目から最終行-1まで繰り返す
For a = 3 To total
 ○最初の行なら
 If a = 3 Then
  ○3行目でA列から26列分を選択している。多分、表題か
  Range(Cells(a, 3), Cells(a, 26)).Select
  ○選択した範囲の下罫線を極細にしている。<<xlBottom⇒xlEdgeBottom>>
  With Selection.Borders(xlBottom)
   .Weight = xlHairline
  End With
 Else

○4行目から、その行のA列と次の行のB列の入力具合を調べている
 burank1 = Worksheets("印刷").Cells(a + 1, 2).Text
 st = Worksheets("印刷").Cells(a, 1).Text
 ○その行のA列が未入力で次の行のB列に入力があった場合、以下の処理をする
 If st = "" And burank1 <> "" Then
  ○その行のB列を選択して『小 計』の文字をセット
  Range(Cells(a, 2), Cells(a, 2)).Select
  ActiveCell.Formula = "小 計"
  With Selection
   ○セットした文字をセルの中央に配置している。<<xlCenter⇒xlHAlignCenter>>
   .HorizontalAlignment = xlCenter
  End With
  ○変数gyoに+1
  gyo = a + 1
  ○その行のA列から26列分を選択。多分、データ行
  Range(Cells(a, 1), Cells(a, 26)).Select
  ○選択したセル範囲の左罫線を細線にしている。<<xlLeft⇒xlEdgeLeft>>
  With Selection.Borders(xlLeft)
   .Weight = xlThin
  End With

この回答への補足

回答ありがとうございました。実は下記のコードの続きがあります。
良ければ意味を教えてください。
よろしくお願いします。


With Selection.Borders(xlEdgeBottom)
.Weight = xlMedium
End With
Range(Cells(a, 3), Cells(a, 4)).Select
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Range(Cells(a, 26), Cells(a, 26)).Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-12]>0,IF(AND(RC[-1]>0,RC[-1]<0.9),""●"",""""),"""")"
Else
If burank1 = "" Then
Range(Cells(a + 1, 1), Cells(a + 1, 26)).Select
With Selection.Borders(xlEdgeLeft)
.Weight = xlThin

End With

With Selection.Borders(xlEdgeBottom)
.Weight = xlMedium

End With
Range(Cells(a + 1, 3), Cells(a + 1, 4)).Select
Selection.Borders(xlLeft).LineStyle = xlNone
Range(Cells(a, 2), Cells(a, 2)).Select
ActiveCell.Formula = "小 計"
With Selection
.HorizontalAlignment = xlHAlignCenter
End With

Range(Cells(a, 1), Cells(a, 26)).Select
With Selection.Borders(xlEdgeLeft)
.Weight = xlThin

End With

With Selection.Borders(xlEdgeBottom)
.Weight = xlMedium

End With
Range(Cells(a, 3), Cells(a, 4)).Select
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Range(Cells(a, 26), Cells(a, 26)).Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-12]>0,IF(AND(RC[-1]>=0,RC[-1]<0.9),""●"",""""),"""")"
a = a + 2

Else

If a = gyo Then
Range(Cells(a, 3), Cells(a, 26)).Select
With Selection.Borders(xlEdgeBottom)
.Weight = xlHairline
End With
Else
'
Range(Cells(a, 1), Cells(a, 2)).Select
Selection.ClearContents
Range(Cells(a, 26), Cells(a, 26)).Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-12]>0,IF(AND(RC[-1]>=0.5,RC[-1]<=0.9),""☆"",IF(AND(RC[-1]>=0,RC[-1]<0.5),""★"","""")),"""")"
End If
End If
'アンダーライン(3:26)
Range(Cells(a, 3), Cells(a, 26)).Select
With Selection.Borders(xlEdgeBottom)
.Weight = xlHairline
End With
End If

End If

'アンダーライン(3:26)


Next a
Range(Cells(total + 1, 1), Cells(total + 1, 26)).Select
With Selection.Borders(xlEdgeLeft)
.Weight = xlThin

End With

With Selection.Borders(xlEdgeBottom)
.Weight = xlMedium

End With
Range(Cells(total + 1, 3), Cells(total + 1, 4)).Select
Selection.Borders(xlEdgeLeft).LineStyle = xlNone

Range("Y3").Select
ActiveCell.Formula = "=IF(n3=0,0,ROUND(x3/n3,1))"
Range("Y3").Select
Selection.Copy
Range(Cells(4, 25), Cells(total + 1, 25)).Select
Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
ActiveSheet.Calculate

Range("a1").Select

補足日時:2002/02/09 09:59
    • good
    • 0
この回答へのお礼

理解していきたいと思います。ありがとうございました。

お礼日時:2002/02/16 08:46

修正漏れが1箇所?関係ないかもしれませんが追記しておきました。



  ○選択したセル範囲の下罫線を中太線(表現が正しい?)にしている。
  With Selection.Borders(xlEdgeBottom)
    .Weight = xlMedium
  End With
  ○その行のC、D列を選択して左罫線をなしにしている
  Range(Cells(a, 3), Cells(a, 4)).Select
  Selection.Borders(xlEdgeLeft).LineStyle = xlNone
  ○その行の26番目の列を選択して算式を登録している
    算式は、その行の12個左の列が正の数値で、
        1つ左のセルが0超、0.9未満なら『●』を表示する
  Range(Cells(a, 26), Cells(a, 26)).Select
  ActiveCell.FormulaR1C1 = _
     "=IF(RC[-12]>0,IF(AND(RC[-1]>0,RC[-1]<0.9),""●"",""""),"""")"
  Else
  ○1行下が未入力の場合
  If burank1 = "" Then
    ○1行下のA列から26列分選択して左罫線を細線にしている
    Range(Cells(a + 1, 1), Cells(a + 1, 26)).Select
    With Selection.Borders(xlEdgeLeft)
      .Weight = xlThin
    End With
    ○下罫線を中太線にしている
    With Selection.Borders(xlEdgeBottom)
      .Weight = xlMedium
    End With
    ○1行下のC、D列を選択して左罫線をなしにしている。<<xlLeft⇒xlEdgeLeft>>
    Range(Cells(a + 1, 3), Cells(a + 1, 4)).Select
    Selection.Borders(xlLeft).LineStyle = xlNone
    ○その行のB列を選択して『小 計』の文字をセット
    Range(Cells(a, 2), Cells(a, 2)).Select
    ActiveCell.Formula = "小 計"
    ○セットした文字をセルの中央に配置している。
    With Selection
      .HorizontalAlignment = xlHAlignCenter
    End With

    ○その行のA列から26列分を選択
    Range(Cells(a, 1), Cells(a, 26)).Select
    ○選択したセル範囲の左罫線を細線にしている。
    With Selection.Borders(xlEdgeLeft)
      .Weight = xlThin
    End With
    ○選択したセル範囲の下罫線を中太線にしている。
    With Selection.Borders(xlEdgeBottom)
      .Weight = xlMedium
    End With
    ○その行C、D列を選択して左罫線をなしにしている
    Range(Cells(a, 3), Cells(a, 4)).Select
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    ○その行の26番目の列を選択して算式を登録している。算式は同じ
    Range(Cells(a, 26), Cells(a, 26)).Select
    ActiveCell.FormulaR1C1 = "=IF(RC[-12]>0,IF(AND(RC[-1]>=0,RC[-1]<0.9),""●"",""""),"""")"
    ○Forループの中でそれを制御する変数aを操作している。恐い!。
     本来やってはいけないはず!別の方法があるはず。
    a = a + 2
  Else
    If a = gyo Then
      Range(Cells(a, 3), Cells(a, 26)).Select
      ○下罫線を細線にしている。
      With Selection.Borders(xlEdgeBottom)
        .Weight = xlHairline
      End With
    Else
      Range(Cells(a, 1), Cells(a, 2)).Select
      Selection.ClearContents
      Range(Cells(a, 26), Cells(a, 26)).Select
      ○算式をセットしている
        算式は、その行の12個左の列が正の数値で、
         1つ左のセルが0.5以上、0.9以下なら『☆』を表示する
         1つ左のセルが0.5未満なら『★』を表示する
      ActiveCell.FormulaR1C1 = "=IF(RC[-12]>0,IF(AND(RC[-1]>=0.5,RC[-1]<=0.9),""☆"",IF(AND(RC[-1]>=0,RC[-1]<0.5),""★"","""")),"""")"
    End If
  End If
  'アンダーライン(3:26)
  Range(Cells(a, 3), Cells(a, 26)).Select
  With Selection.Borders(xlEdgeBottom)
  ○下罫線を細線にしている。
    .Weight = xlHairline
  End With
End If

End If

'アンダーライン(3:26)
Next a

○トータル行を選択
Range(Cells(total + 1, 1), Cells(total + 1, 26)).Select
With Selection.Borders(xlEdgeLeft)
  ○選択したセル範囲の左罫線を細線にしている。
  .Weight = xlThin
End With

With Selection.Borders(xlEdgeBottom)
  ○選択したセル範囲の下罫線を中太線にしている。
  .Weight = xlMedium
End With
○その行C、D列を選択して左罫線をなしにしている
Range(Cells(total + 1, 3), Cells(total + 1, 4)).Select
Selection.Borders(xlEdgeLeft).LineStyle = xlNone

○セルY3を選択して算式をセット
  算式は、N3がゼロでなかったらX3をN3で割って、小数1位で四捨五入
Range("Y3").Select
ActiveCell.Formula = "=IF(n3=0,0,ROUND(x3/n3,1))"
Range("Y3").Select
Selection.Copy
○Y3の算式をデータの25列目にコピーしている
Range(Cells(4, 25), Cells(total + 1, 25)).Select
Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
○再計算している
ActiveSheet.Calculate

Range("a1").Select

※aでLoopしているForループの途中に『a = a + 2』がありますが問題なく動いてるんですよね。
 全体を通して行っていることは、不定行の小計を計算して、それを罫線付の印刷で行おうとしているように思えます。
 印刷用のシートにページ単位でデータをはきだし、小計行の罫線パターンを別に用意しておいて書式をコピーすれば簡単になりそうですね。
 表示書式や割算の算式も事前に作っておけばマクロの中で定義する必要がなくなるわけです。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!