私はVBAが初めてです。定数セルを定数テキストで埋める関数を作成しようとしています。これは私のコードです:
Public Function PrepareSpreadSheet()
Range("B5").Select
ActiveCell.FormulaR1C1 = "Sun"
Range("C5").Select
ActiveCell.FormulaR1C1 = "Mon"
Range("D5").Select
ActiveCell.FormulaR1C1 = "Tue"
Range("J5").Select
ActiveCell.FormulaR1C1 = "Total"
Range("B5:J5").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Function
サブからこの関数を呼び出しています:
Sub ReadTxtFile()
PrepareSpreadSheet
End Sub
これを実行しても何も起こりません。デバッグすると、指定したセルにテキストが入力されていることがわかりますが、関数が終了すると消えます。
これを修正する方法を説明していただけますか?
ありがとう、リー