I'm new with VBA. I'm trying to write a function which fills some constant cells with constant text. This is my code:
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
I'm calling this function from my sub:
Sub ReadTxtFile()
PrepareSpreadSheet
End Sub
When I run this nothing happens. When debugging, I see that the text is entered to the specified cells, but then disappears when the function exits.
Can you please explain how to fix this?
Thanks, Li