Log.log(work)

いろんな作業メモ

久々にマクロ

マクロ作ろうとしたらド忘れしてたおまじない。

Option Explicit

変数の宣言を厳密にしてくれる。
業務で使うわけじゃなくて、簡単ツールを作りたかっただけなのであってもなくてもいいんだけど。

しかし久々にVBA触ったけど、すっかり忘れてるね!
ネット万歳。

Option Explicit

Sub Macro1()
'こぴぺ

    Dim index As Integer
    Dim cnt As Integer
    Dim custNum As Integer
    
    index = 1
    custNum = 1
    For cnt = 5 To 20006
        
        Worksheets(1).Range(Cells(cnt, 2), Cells(cnt, 2)) = "HOGE" & Format(custNum, "0000000")
        Worksheets("Sheet1").Range(Cells(index, 3), Cells(index, 55)).Copy Worksheets("Sheet1").Range(Cells(cnt, 3), Cells(cnt, 55))
        
        index = index + 1
        custNum = custNum + 1
        
    Next

End Sub


subは返り値なし、functionは返り値あり。
Worksheetsはシート名でも数値(1はじまり)でも可。
Rangeの指定は適当。