電子書籍の厳選無料作品が豊富!

下記マクロを短いコード(一つのコード)に変更する方法を教えてください。
Sub 採光面積()
Sheets("Table 2").Select
Range("$AC$8").Formula = "=IFERROR(ROUNDUP($Y$8*数式! $C$1,2),"""")"
Range("$AC$14").Formula = "=IFERROR(round($Y$14*数式! $C$2,2),"""")"
Range("$AC$20").Formula = "=IFERROR(round($Y$20*数式! $C$3,2),"""")"
Range("$AC$26").Formula = "=IFERROR(round($Y$26*数式! $C$4,2),"""")"
Range("$AC$32").Formula = "=IFERROR(round($Y$32*数式! $C$5,2),"""")"
Range("$AC$38").Formula = "=IFERROR(round($Y$38*数式! $C$6,2),"""")"
Range("$AC$44").Formula = "=IFERROR(round($Y$44*数式! $C$7,2),"""")"
Range("$AC$50").Formula = "=IFERROR(round($Y$50*数式! $C$8,2),"""")"
Range("$AC$56").Formula = "=IFERROR(round($Y$56*数式! $C$9,2),"""")"
Range("$AC$62").Formula = "=IFERROR(round($Y$62*数式! $C$10,2),"""")"
Range("$AC$68").Formula = "=IFERROR(round($Y$68*数式! $C$11,2),"""")"
Range("$AC$74").Formula = "=IFERROR(round($Y$74*数式! $C$12,2),"""")"
Range("$AC$80").Formula = "=IFERROR(round($Y$80*数式! $C$13,2),"""")"
Range("$AC$86").Formula = "=IFERROR(round($Y$86*数式! $C$14,2),"""")"
Range("$AC$92").Formula = "=IFERROR(round($Y$92*数式! $C$15,2),"""")"
Range("$AC$98").Formula = "=IFERROR(round($Y$98*数式! $C$16,2),"""")"
Range("$AC$104").Formula = "=IFERROR(round($Y$104*数式! $C$17,2),"""")"
Range("$AC$110").Formula = "=IFERROR(round($Y$110*数式! $C$18,2),"""")"
Range("$AC$116").Formula = "=IFERROR(round($Y$116*数式! $C$19,2),"""")"
Range("$AC$122").Formula = "=IFERROR(round($Y$122*数式! $C$20,2),"""")"
Sheets("Table 2").Select
Range("X2").Select
End Sub
以上となります。
宜しくお願い致します。

質問者からの補足コメント

  • うーん・・・

    回答ありがとうございました。
    もう少し詳しく教えて頂けますでしょうか。
    よろしくお願いいたします。

    No.1の回答に寄せられた補足コメントです。 補足日時:2024/09/10 10:18
  • うーん・・・

    回答ありがとうございます。
    申し訳ございません。
    全てが「ROUNDUP」の間違えです。
    よろしくお願いいたします。

    No.3の回答に寄せられた補足コメントです。 補足日時:2024/09/10 12:09

A 回答 (4件)

以下のようにしてください。



Sub 採光面積()
Dim i As Long
Dim r As Long
Dim str1 As String
Dim str2 As String
Sheets("Table 2").Select
For i = 1 To 20
r = i * 6 + 2
str1 = "$AC$" & r
str2 = "=IFERROR(ROUNDUP($Y$" & r & "*数式! $C$" & i & ",2),"""")"
Range(str1) = str2
Next
Range("X2").Select
End Sub
    • good
    • 0
この回答へのお礼

何時も助けて頂けてありがとうございます。
上手くできました。

お礼日時:2024/09/10 12:27

$AC$8 のみがROUNDUPした結果を格納しています。


$AC$8以外の行は、roundになっています。
これで、間違いないでしょうか。
それとも、どちらかが誤っているのでしょうか。
この回答への補足あり
    • good
    • 0

数式を入れる20行は、最初の


Range("$AC$8").Formula = "=IFERROR(ROUNDUP($Y$8*数式! $C$1,2),"""")"
の $8 と $1 を変化させているだけですから、No.1のForループで回せば、For~Nextの間は1行で済むことになります。
    • good
    • 0

For iRow=1 to 20


******
Next

iRow * 6 + 2 で、8,14,20,26・・・・・122 と変化します。
この回答への補足あり
    • good
    • 0

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


おすすめ情報